mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Merge branch 'main' into auto-snake-case
This commit is contained in:
commit
cd0e2a4474
24 changed files with 95 additions and 51 deletions
|
@ -874,7 +874,7 @@ map_with_index_help = \src, dest, func, index, length ->
|
|||
## All of these options are compatible with the others. For example, you can use `At` or `After`
|
||||
## with `start` regardless of what `end` and `step` are set to.
|
||||
range : _
|
||||
range = \{ start, end, step ? 0 } ->
|
||||
range = \{ start, end, step ?? 0 } ->
|
||||
{ calc_next, step_is_positive } =
|
||||
if step == 0 then
|
||||
when T(start, end) is
|
||||
|
|
|
@ -617,8 +617,8 @@ is_gte : Num a, Num a -> Bool
|
|||
##
|
||||
## If either argument is [*NaN*](Num.is_nan), returns `Bool.false` no matter what. (*NaN*
|
||||
## is [defined to be unordered](https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN).)
|
||||
is_approx_eq : Frac a, Frac a, { rtol ? Frac a, atol ? Frac a } -> Bool
|
||||
is_approx_eq = \x, y, { rtol ? 0.00001, atol ? 0.00000001 } ->
|
||||
is_approx_eq : Frac a, Frac a, { rtol ?? Frac a, atol ?? Frac a } -> Bool
|
||||
is_approx_eq = \x, y, { rtol ?? 0.00001, atol ?? 0.00000001 } ->
|
||||
eq = x <= y && x >= y
|
||||
meets_tolerance = Num.abs_diff(x, y) <= Num.max(atol, (rtol * Num.max(Num.abs(x), Num.abs(y))))
|
||||
eq || meets_tolerance
|
||||
|
|
|
@ -386,7 +386,7 @@ impl<'a> Nodify<'a> for AssignedField<'a, TypeAnnotation<'a>> {
|
|||
assigned_field_value_to_node(n.into_bump_str(), arena, sp, &value.value, ":", flags)
|
||||
}
|
||||
AssignedField::OptionalValue(name, sp, value) => {
|
||||
assigned_field_value_to_node(name.value, arena, sp, &value.value, "?", flags)
|
||||
assigned_field_value_to_node(name.value, arena, sp, &value.value, "??", flags)
|
||||
}
|
||||
AssignedField::LabelOnly(name) => NodeInfo {
|
||||
before: &[],
|
||||
|
@ -512,7 +512,7 @@ fn format_assigned_field_help<T>(
|
|||
|
||||
buf.spaces(separator_spaces);
|
||||
buf.indent(indent);
|
||||
buf.push('?');
|
||||
buf.push_str("??");
|
||||
buf.spaces(1);
|
||||
ann.value.format(buf, indent);
|
||||
}
|
||||
|
|
|
@ -701,16 +701,8 @@ fn fmt_apply(
|
|||
if !expr.before.is_empty() {
|
||||
format_spaces(buf, expr.before, Newlines::Yes, indent);
|
||||
}
|
||||
expr.item.format_with_options(
|
||||
buf,
|
||||
if use_commas_and_parens {
|
||||
Parens::NotNeeded
|
||||
} else {
|
||||
Parens::InApply
|
||||
},
|
||||
Newlines::Yes,
|
||||
indent,
|
||||
);
|
||||
expr.item
|
||||
.format_with_options(buf, Parens::InApply, Newlines::Yes, indent);
|
||||
|
||||
if use_commas_and_parens {
|
||||
buf.push('(');
|
||||
|
|
|
@ -268,7 +268,7 @@ fn fmt_pattern_only(
|
|||
Pattern::OptionalField(name, loc_pattern) => {
|
||||
buf.indent(indent);
|
||||
snakify_camel_ident(buf, name);
|
||||
buf.push_str(" ?");
|
||||
buf.push_str(" ??");
|
||||
buf.spaces(1);
|
||||
loc_pattern.format(buf, indent);
|
||||
}
|
||||
|
|
|
@ -4541,8 +4541,8 @@ mod test_reporting {
|
|||
4│ f : { foo bar }
|
||||
^
|
||||
|
||||
I was expecting to see a colon, question mark, comma or closing curly
|
||||
brace.
|
||||
I was expecting to see a colon, two question marks (??), comma or
|
||||
closing curly brace.
|
||||
"
|
||||
);
|
||||
|
||||
|
|
|
@ -3587,7 +3587,10 @@ pub fn record_field<'a>() -> impl Parser<'a, RecordField<'a>, ERecord<'a>> {
|
|||
optional(either(
|
||||
and(byte(b':', ERecord::Colon), record_field_expr()),
|
||||
and(
|
||||
byte(b'?', ERecord::QuestionMark),
|
||||
and(
|
||||
byte(b'?', ERecord::QuestionMark),
|
||||
optional(byte(b'?', ERecord::SecondQuestionMark)),
|
||||
),
|
||||
spaces_before(specialize_err_ref(ERecord::Expr, loc_expr(true))),
|
||||
),
|
||||
)),
|
||||
|
|
|
@ -1219,6 +1219,7 @@ impl<'a> Normalize<'a> for ERecord<'a> {
|
|||
ERecord::UnderscoreField(_pos) => ERecord::Field(Position::zero()),
|
||||
ERecord::Colon(_) => ERecord::Colon(Position::zero()),
|
||||
ERecord::QuestionMark(_) => ERecord::QuestionMark(Position::zero()),
|
||||
ERecord::SecondQuestionMark(_) => ERecord::SecondQuestionMark(Position::zero()),
|
||||
ERecord::Arrow(_) => ERecord::Arrow(Position::zero()),
|
||||
ERecord::Ampersand(_) => ERecord::Ampersand(Position::zero()),
|
||||
ERecord::Expr(inner_err, _) => {
|
||||
|
@ -1393,6 +1394,9 @@ impl<'a> Normalize<'a> for ETypeAbilityImpl<'a> {
|
|||
ETypeAbilityImpl::Space(*inner_err, Position::zero())
|
||||
}
|
||||
ETypeAbilityImpl::QuestionMark(_) => ETypeAbilityImpl::QuestionMark(Position::zero()),
|
||||
ETypeAbilityImpl::SecondQuestionMark(_) => {
|
||||
ETypeAbilityImpl::SecondQuestionMark(Position::zero())
|
||||
}
|
||||
ETypeAbilityImpl::Ampersand(_) => ETypeAbilityImpl::Ampersand(Position::zero()),
|
||||
ETypeAbilityImpl::Expr(inner_err, _) => {
|
||||
ETypeAbilityImpl::Expr(arena.alloc(inner_err.normalize(arena)), Position::zero())
|
||||
|
@ -1471,7 +1475,8 @@ impl<'a> Normalize<'a> for ETypeRecord<'a> {
|
|||
ETypeRecord::Open(_) => ETypeRecord::Open(Position::zero()),
|
||||
ETypeRecord::Field(_) => ETypeRecord::Field(Position::zero()),
|
||||
ETypeRecord::Colon(_) => ETypeRecord::Colon(Position::zero()),
|
||||
ETypeRecord::Optional(_) => ETypeRecord::Optional(Position::zero()),
|
||||
ETypeRecord::OptionalFirst(_) => ETypeRecord::OptionalFirst(Position::zero()),
|
||||
ETypeRecord::OptionalSecond(_) => ETypeRecord::OptionalSecond(Position::zero()),
|
||||
ETypeRecord::Type(inner_err, _) => {
|
||||
ETypeRecord::Type(arena.alloc(inner_err.normalize(arena)), Position::zero())
|
||||
}
|
||||
|
@ -1491,7 +1496,8 @@ impl<'a> Normalize<'a> for PRecord<'a> {
|
|||
PRecord::Open(_) => PRecord::Open(Position::zero()),
|
||||
PRecord::Field(_) => PRecord::Field(Position::zero()),
|
||||
PRecord::Colon(_) => PRecord::Colon(Position::zero()),
|
||||
PRecord::Optional(_) => PRecord::Optional(Position::zero()),
|
||||
PRecord::OptionalFirst(_) => PRecord::OptionalFirst(Position::zero()),
|
||||
PRecord::OptionalSecond(_) => PRecord::OptionalSecond(Position::zero()),
|
||||
PRecord::Pattern(inner_err, _) => {
|
||||
PRecord::Pattern(arena.alloc(inner_err.normalize(arena)), Position::zero())
|
||||
}
|
||||
|
|
|
@ -683,6 +683,7 @@ pub enum ERecord<'a> {
|
|||
UnderscoreField(Position),
|
||||
Colon(Position),
|
||||
QuestionMark(Position),
|
||||
SecondQuestionMark(Position),
|
||||
Arrow(Position),
|
||||
Ampersand(Position),
|
||||
|
||||
|
@ -706,6 +707,7 @@ impl<'a> ERecord<'a> {
|
|||
| ERecord::UnderscoreField(p)
|
||||
| ERecord::Colon(p)
|
||||
| ERecord::QuestionMark(p)
|
||||
| ERecord::SecondQuestionMark(p)
|
||||
| ERecord::Arrow(p)
|
||||
| ERecord::Ampersand(p)
|
||||
| ERecord::Space(_, p) => Region::from_pos(*p),
|
||||
|
@ -1107,7 +1109,8 @@ pub enum PRecord<'a> {
|
|||
|
||||
Field(Position),
|
||||
Colon(Position),
|
||||
Optional(Position),
|
||||
OptionalFirst(Position),
|
||||
OptionalSecond(Position),
|
||||
|
||||
Pattern(&'a EPattern<'a>, Position),
|
||||
Expr(&'a EExpr<'a>, Position),
|
||||
|
@ -1127,7 +1130,8 @@ impl<'a> PRecord<'a> {
|
|||
| PRecord::Open(p)
|
||||
| PRecord::Field(p)
|
||||
| PRecord::Colon(p)
|
||||
| PRecord::Optional(p)
|
||||
| PRecord::OptionalFirst(p)
|
||||
| PRecord::OptionalSecond(p)
|
||||
| PRecord::Space(_, p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
|
@ -1244,7 +1248,8 @@ pub enum ETypeRecord<'a> {
|
|||
|
||||
Field(Position),
|
||||
Colon(Position),
|
||||
Optional(Position),
|
||||
OptionalFirst(Position),
|
||||
OptionalSecond(Position),
|
||||
Type(&'a EType<'a>, Position),
|
||||
|
||||
Space(BadInputError, Position),
|
||||
|
@ -1266,7 +1271,8 @@ impl<'a> ETypeRecord<'a> {
|
|||
| ETypeRecord::Open(p)
|
||||
| ETypeRecord::Field(p)
|
||||
| ETypeRecord::Colon(p)
|
||||
| ETypeRecord::Optional(p)
|
||||
| ETypeRecord::OptionalFirst(p)
|
||||
| ETypeRecord::OptionalSecond(p)
|
||||
| ETypeRecord::Space(_, p)
|
||||
| ETypeRecord::IndentOpen(p)
|
||||
| ETypeRecord::IndentColon(p)
|
||||
|
@ -1394,6 +1400,7 @@ pub enum ETypeAbilityImpl<'a> {
|
|||
|
||||
Prefix(Position),
|
||||
QuestionMark(Position),
|
||||
SecondQuestionMark(Position),
|
||||
Ampersand(Position),
|
||||
Expr(&'a EExpr<'a>, Position),
|
||||
IndentBar(Position),
|
||||
|
@ -1416,6 +1423,7 @@ impl<'a> ETypeAbilityImpl<'a> {
|
|||
| ETypeAbilityImpl::Space(_, p)
|
||||
| ETypeAbilityImpl::Prefix(p)
|
||||
| ETypeAbilityImpl::QuestionMark(p)
|
||||
| ETypeAbilityImpl::SecondQuestionMark(p)
|
||||
| ETypeAbilityImpl::Ampersand(p)
|
||||
| ETypeAbilityImpl::IndentBar(p)
|
||||
| ETypeAbilityImpl::IndentAmpersand(p) => Region::from_pos(*p),
|
||||
|
@ -1435,6 +1443,7 @@ impl<'a> From<ERecord<'a>> for ETypeAbilityImpl<'a> {
|
|||
ERecord::Space(s, p) => ETypeAbilityImpl::Space(s, p),
|
||||
ERecord::Prefix(p) => ETypeAbilityImpl::Prefix(p),
|
||||
ERecord::QuestionMark(p) => ETypeAbilityImpl::QuestionMark(p),
|
||||
ERecord::SecondQuestionMark(p) => ETypeAbilityImpl::SecondQuestionMark(p),
|
||||
ERecord::Ampersand(p) => ETypeAbilityImpl::Ampersand(p),
|
||||
ERecord::Expr(e, p) => ETypeAbilityImpl::Expr(e, p),
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::blankspace::{space0_before_optional_after, space0_e, spaces, spaces_b
|
|||
use crate::ident::{lowercase_ident, parse_ident, Accessor, Ident};
|
||||
use crate::keyword;
|
||||
use crate::parser::{
|
||||
self, backtrackable, byte, collection_trailing_sep_e, fail_when, loc, map, map_with_arena,
|
||||
self, and, backtrackable, byte, collection_trailing_sep_e, fail_when, loc, map, map_with_arena,
|
||||
optional, skip_first, skip_second, specialize_err, specialize_err_ref, then, three_bytes,
|
||||
two_bytes, zero_or_more, EPattern, PInParens, PList, PRecord, Parser,
|
||||
};
|
||||
|
@ -551,7 +551,10 @@ fn record_pattern_field<'a>() -> impl Parser<'a, Loc<Pattern<'a>>, PRecord<'a>>
|
|||
// (This is true in both literals and types.)
|
||||
let (_, opt_loc_val, state) = optional(either(
|
||||
byte(b':', PRecord::Colon),
|
||||
byte(b'?', PRecord::Optional),
|
||||
and(
|
||||
byte(b'?', PRecord::OptionalFirst),
|
||||
optional(byte(b'?', PRecord::OptionalSecond)),
|
||||
),
|
||||
))
|
||||
.parse(arena, state, min_indent)?;
|
||||
|
||||
|
|
|
@ -588,7 +588,10 @@ fn record_type_field<'a>() -> impl Parser<'a, AssignedField<'a, TypeAnnotation<'
|
|||
// (This is true in both literals and types.)
|
||||
let (_, opt_loc_val, state) = optional(either(
|
||||
byte(b':', ETypeRecord::Colon),
|
||||
byte(b'?', ETypeRecord::Optional),
|
||||
and(
|
||||
byte(b'?', ETypeRecord::OptionalFirst),
|
||||
optional(byte(b'?', ETypeRecord::OptionalSecond)),
|
||||
),
|
||||
))
|
||||
.parse(arena, state, min_indent)?;
|
||||
|
||||
|
|
|
@ -102,10 +102,7 @@ fn round_trip_once(input: Input<'_>, options: Options) -> Option<String> {
|
|||
let arena = Bump::new();
|
||||
|
||||
let actual = match input.parse_in(&arena) {
|
||||
Ok(a) => {
|
||||
println!("actual {a:#?}");
|
||||
a
|
||||
}
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
if options.minimize_initial_parse_error {
|
||||
return Some(format!("Initial parse failed: {:?}", e.normalize(&arena)));
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
\I { p ? Y
|
||||
\I { p ?? Y
|
||||
Y } [] ->
|
||||
K # (
|
|
@ -1,5 +1,5 @@
|
|||
O
|
||||
{ p ? if
|
||||
{ p ?? if
|
||||
a
|
||||
then
|
||||
A
|
||||
|
|
|
@ -1 +1 @@
|
|||
module { x, y ? 0 } -> [menu]
|
||||
module { x, y ?? 0 } -> [menu]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
l?
|
||||
l??
|
||||
"""
|
||||
""",
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
i? p,
|
||||
i?? p,
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
{ i ? Y } = p
|
||||
{ i ?? Y } = p
|
||||
Q
|
|
@ -1,5 +1,5 @@
|
|||
0 : {
|
||||
i
|
||||
? d,
|
||||
?? d,
|
||||
}
|
||||
O
|
|
@ -1,4 +1,4 @@
|
|||
{ e ? f
|
||||
{ e ?? f
|
||||
4 } = f
|
||||
e
|
||||
r
|
|
@ -1,8 +1,8 @@
|
|||
M
|
||||
{ s ? s
|
||||
{ s ?? s
|
||||
{ J &
|
||||
} }
|
||||
{ s ? s
|
||||
{ s ?? s
|
||||
{ J &
|
||||
} } : p
|
||||
y
|
|
@ -2497,13 +2497,13 @@ mod test_fmt {
|
|||
expr_formats_to(
|
||||
indoc!(
|
||||
r"
|
||||
f : { a ?Str }
|
||||
f : { a ??Str }
|
||||
|
||||
f"
|
||||
),
|
||||
indoc!(
|
||||
r"
|
||||
f : { a ? Str }
|
||||
f : { a ?? Str }
|
||||
|
||||
f"
|
||||
),
|
||||
|
@ -2513,7 +2513,7 @@ mod test_fmt {
|
|||
indoc!(
|
||||
r"
|
||||
f : {
|
||||
a ?Str,
|
||||
a ??Str,
|
||||
}
|
||||
|
||||
f"
|
||||
|
@ -2521,7 +2521,7 @@ mod test_fmt {
|
|||
indoc!(
|
||||
r"
|
||||
f : {
|
||||
a ? Str,
|
||||
a ?? Str,
|
||||
}
|
||||
|
||||
f"
|
||||
|
@ -2743,7 +2743,7 @@ mod test_fmt {
|
|||
r"
|
||||
f :
|
||||
{
|
||||
someField ? Int * # comment 1
|
||||
someField ?? Int * # comment 1
|
||||
,
|
||||
# comment 2
|
||||
}
|
||||
|
@ -2753,7 +2753,7 @@ mod test_fmt {
|
|||
indoc!(
|
||||
r"
|
||||
f : {
|
||||
some_field ? Int *, # comment 1
|
||||
some_field ?? Int *, # comment 1
|
||||
# comment 2
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue