Skip to content

Commit

Permalink
Merge branch 'main' into auto-snake-case
Browse files Browse the repository at this point in the history
  • Loading branch information
smores56 committed Jan 6, 2025
2 parents 0f90f53 + 01da957 commit cd0e2a4
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 51 deletions.
2 changes: 1 addition & 1 deletion crates/compiler/builtins/roc/List.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/builtins/roc/Num.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/fmt/src/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: &[],
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 2 additions & 10 deletions crates/compiler/fmt/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('(');
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/fmt/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/load/tests/test_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"
);

Expand Down
5 changes: 4 additions & 1 deletion crates/compiler/parse/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
),
)),
Expand Down
10 changes: 8 additions & 2 deletions crates/compiler/parse/src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _) => {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down
17 changes: 13 additions & 4 deletions crates/compiler/parse/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ pub enum ERecord<'a> {
UnderscoreField(Position),
Colon(Position),
QuestionMark(Position),
SecondQuestionMark(Position),
Arrow(Position),
Ampersand(Position),

Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
}
}
Expand Down Expand Up @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -1394,6 +1400,7 @@ pub enum ETypeAbilityImpl<'a> {

Prefix(Position),
QuestionMark(Position),
SecondQuestionMark(Position),
Ampersand(Position),
Expr(&'a EExpr<'a>, Position),
IndentBar(Position),
Expand All @@ -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),
Expand All @@ -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),
}
Expand Down
7 changes: 5 additions & 2 deletions crates/compiler/parse/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)?;

Expand Down
5 changes: 4 additions & 1 deletion crates/compiler/parse/src/type_annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
5 changes: 1 addition & 4 deletions crates/compiler/test_syntax/src/minimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
\I { p ? Y
\I { p ?? Y
Y } [] ->
K # (
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
O
{ p ? if
{ p ?? if
a
then
A
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module { x, y ? 0 } -> [menu]
module { x, y ?? 0 } -> [menu]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
l?
l??
"""
""",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
i? p,
i?? p,
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{ i ? Y } = p
{ i ?? Y } = p
Q
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0 : {
i
? d,
?? d,
}
O
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ e ? f
{ e ?? f
4 } = f
e
r
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
M
{ s ? s
{ s ?? s
{ J &
} }
{ s ? s
{ s ?? s
{ J &
} } : p
y
12 changes: 6 additions & 6 deletions crates/compiler/test_syntax/tests/test_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand All @@ -2513,15 +2513,15 @@ mod test_fmt {
indoc!(
r"
f : {
a ?Str,
a ??Str,
}
f"
),
indoc!(
r"
f : {
a ? Str,
a ?? Str,
}
f"
Expand Down Expand Up @@ -2743,7 +2743,7 @@ mod test_fmt {
r"
f :
{
someField ? Int * # comment 1
someField ?? Int * # comment 1
,
# comment 2
}
Expand All @@ -2753,7 +2753,7 @@ mod test_fmt {
indoc!(
r"
f : {
some_field ? Int *, # comment 1
some_field ?? Int *, # comment 1
# comment 2
}
Expand Down
6 changes: 3 additions & 3 deletions crates/reporting/src/error/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,7 @@ fn to_precord_report<'a>(
PRecord::Colon(_) => {
unreachable!("because `foo` is a valid field; the colon is not required")
}
PRecord::Optional(_) => {
PRecord::OptionalFirst(_) | PRecord::OptionalSecond(_) => {
unreachable!("because `foo` is a valid field; the question mark is not required")
}

Expand Down Expand Up @@ -2889,7 +2889,7 @@ fn to_trecord_report<'a>(
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity),
alloc.concat([
alloc.reflow(
r"I was expecting to see a colon, question mark, comma or closing curly brace.",
r"I was expecting to see a colon, two question marks (??), comma or closing curly brace.",
),
]),
]);
Expand Down Expand Up @@ -2976,7 +2976,7 @@ fn to_trecord_report<'a>(
ETypeRecord::Colon(_) => {
unreachable!("because `foo` is a valid field; the colon is not required")
}
ETypeRecord::Optional(_) => {
ETypeRecord::OptionalFirst(_) | ETypeRecord::OptionalSecond(_) => {
unreachable!("because `foo` is a valid field; the question mark is not required")
}

Expand Down
Loading

0 comments on commit cd0e2a4

Please sign in to comment.