Improve parsing of negative + not'd exprs

This commit is contained in:
Joshua Warner 2024-12-01 11:40:57 -08:00
parent 61d885039d
commit d4301e86a3
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
31 changed files with 530 additions and 102 deletions

View file

@ -0,0 +1,51 @@
SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-3,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@0-3 BinOps(
[
(
@0-1 Var {
module_name: "",
ident: "i",
},
@1-2 LessThan,
),
],
@2-3 Num(
"2",
),
),
),
],
},
@4-8 SpaceBefore(
ParensAround(
Num(
"-6",
),
),
[
Newline,
],
),
),
[
Newline,
],
)

View file

@ -0,0 +1,2 @@
i<2
(-6)

View file

@ -0,0 +1,51 @@
SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-12,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Annotation(
@0-10 StrLiteral(
Line(
[
Interpolated(
@5-6 Var {
module_name: "",
ident: "g",
},
),
],
),
),
@11-12 BoundVariable(
"q",
),
),
],
},
@13-14 SpaceBefore(
Var {
module_name: "",
ident: "f",
},
[
Newline,
],
),
),
[
Newline,
],
)

View file

@ -0,0 +1,2 @@
"""$(g)""":q
f

View file

@ -1,39 +1,56 @@
BinOps(
[
(
@0-1 Var {
module_name: "",
ident: "i",
},
@1-2 GreaterThan,
),
],
@2-10 Apply(
@2-7 SpaceAfter(
Closure(
[
@3-4 Identifier {
ident: "s",
},
],
@6-7 Var {
module_name: "",
ident: "s",
},
),
[
Newline,
],
),
[
@8-10 UnaryOp(
@9-10 Var {
module_name: "",
ident: "a",
},
@8-9 Negate,
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-7,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@0-7 BinOps(
[
(
@0-1 Var {
module_name: "",
ident: "i",
},
@1-2 GreaterThan,
),
],
@2-7 Closure(
[
@3-4 Identifier {
ident: "s",
},
],
@6-7 Var {
module_name: "",
ident: "s",
},
),
),
),
],
Space,
},
@8-10 SpaceBefore(
UnaryOp(
@9-10 Var {
module_name: "",
ident: "a",
},
@8-9 Negate,
),
[
Newline,
],
),
)

View file

@ -0,0 +1,41 @@
SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-4,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Body(
@0-2 RecordDestructure(
[],
),
@3-4 Tag(
"B",
),
),
],
},
@5-6 SpaceBefore(
Tag(
"I",
),
[
Newline,
],
),
),
[
Newline,
],
)

View file

@ -0,0 +1,46 @@
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-1,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@0-1 Var {
module_name: "",
ident: "f",
},
),
],
},
@2-6 SpaceBefore(
UnaryOp(
@4-6 SpaceBefore(
UnaryOp(
@5-6 Var {
module_name: "",
ident: "f",
},
@4-5 Not,
),
[
Newline,
],
),
@2-3 Not,
),
[
Newline,
],
),
)

View file

@ -0,0 +1,3 @@
f
!
!f

View file

@ -0,0 +1,11 @@
UnaryOp(
@1-8 UnaryOp(
@2-8 Str(
Block(
[],
),
),
@1-2 Negate,
),
@0-1 Negate,
)

View file

@ -0,0 +1,15 @@
SpaceAfter(
UnaryOp(
@1-3 UnaryOp(
@2-3 Var {
module_name: "",
ident: "h",
},
@1-2 Not,
),
@0-1 Negate,
),
[
Newline,
],
)

View file

@ -1,35 +1,52 @@
BinOps(
[
(
@0-1 Var {
module_name: "",
ident: "n",
},
@1-2 Star,
),
],
@2-8 Apply(
@2-3 SpaceAfter(
Var {
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-3,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@0-3 BinOps(
[
(
@0-1 Var {
module_name: "",
ident: "n",
},
@1-2 Star,
),
],
@2-3 Var {
module_name: "",
ident: "f",
},
),
),
],
},
@6-8 SpaceBefore(
UnaryOp(
@7-8 Var {
module_name: "",
ident: "f",
},
[
Newline,
LineComment(
"",
),
],
@6-7 Negate,
),
[
@6-8 UnaryOp(
@7-8 Var {
module_name: "",
ident: "f",
},
@6-7 Negate,
Newline,
LineComment(
"",
),
],
Space,
),
)

View file

@ -0,0 +1,61 @@
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-1,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@0-1 Var {
module_name: "",
ident: "d",
},
),
],
},
@2-12 SpaceBefore(
Backpassing(
[
@2-3 SpaceAfter(
Identifier {
ident: "t",
},
[
LineComment(
"",
),
],
),
],
@8-9 Var {
module_name: "",
ident: "b",
},
@10-12 SpaceBefore(
UnaryOp(
@11-12 Var {
module_name: "",
ident: "f",
},
@10-11 Negate,
),
[
Newline,
],
),
),
[
Newline,
],
),
)

View file

@ -0,0 +1,4 @@
d
t #
<-b
-f

View file

@ -25,26 +25,43 @@ Defs(
},
Return(
@2-16 SpaceBefore(
Apply(
@11-12 SpaceAfter(
Var {
module_name: "",
ident: "f",
},
[
Newline,
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
),
[
@14-16 UnaryOp(
regions: [
@11-12,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@11-12 Var {
module_name: "",
ident: "f",
},
),
],
},
@14-16 SpaceBefore(
UnaryOp(
@15-16 Var {
module_name: "",
ident: "f",
},
@14-15 Negate,
),
],
Space,
[
Newline,
],
),
),
[
LineComment(

View file

@ -0,0 +1,36 @@
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-1,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
Stmt(
@0-1 Var {
module_name: "",
ident: "i",
},
),
],
},
@2-6 SpaceBefore(
ParensAround(
Num(
"-2",
),
),
[
Newline,
],
),
)

View file

@ -287,6 +287,7 @@ mod test_snapshots {
pass/annotation_apply_newlines.expr,
pass/annotation_comment_before_colon.expr,
pass/applies_in_binop.expr,
pass/apply_binop_switch.expr,
pass/apply_closure_pizza.expr,
pass/apply_parenthetical_tag_args.expr,
pass/apply_tag.expr,
@ -302,6 +303,7 @@ mod test_snapshots {
pass/basic_tuple.expr,
pass/basic_var.expr,
pass/binop_apply_complex.expr,
pass/block_string_ann.expr,
pass/call_bang.expr,
pass/call_bang_no_space.expr,
pass/closure_in_binop_with_spaces.expr,
@ -341,6 +343,7 @@ mod test_snapshots {
pass/empty_package_header.header,
pass/empty_platform_header.header,
pass/empty_record.expr,
pass/empty_record_assignment.expr,
pass/empty_record_update.expr,
pass/empty_string.expr,
pass/equals.expr,
@ -350,6 +353,7 @@ mod test_snapshots {
pass/expect_single_line.expr,
pass/extra_newline.expr,
pass/extra_newline_in_parens.expr,
pass/f_not_not_f.expr,
pass/float_with_underscores.expr,
pass/fn_with_record_arg.expr,
pass/full_app_header.header,
@ -385,8 +389,10 @@ mod test_snapshots {
pass/lowest_int.expr,
pass/min_parens_number.expr,
pass/minimal_app_header.header,
pass/minus_minus_block_string.expr,
pass/minus_minus_six.expr,
pass/minus_newline_minus_minus.expr,
pass/minus_not_h.expr,
pass/minus_twelve_minus_five.expr,
pass/mixed_docs.expr,
pass/module_def_newline.moduledefs,
@ -402,6 +408,7 @@ mod test_snapshots {
pass/multi_backpassing_with_apply.expr,
pass/multi_char_string.expr,
pass/multiline_apply_equals_multiline_apply.expr,
pass/multiline_backpassing.expr,
pass/multiline_binop_when_with_comments.expr,
pass/multiline_str_in_pat.expr,
pass/multiline_string.expr,
@ -518,6 +525,7 @@ mod test_snapshots {
pass/spaced_singleton_list.expr,
pass/spaces_inside_empty_list.expr,
pass/standalone_module_defs.moduledefs,
pass/stmt_parens_minus.expr,
pass/str_block_multiple_newlines.expr,
pass/string_without_escape.expr,
pass/sub_var_with_spaces.expr,