Parse assignment patterns with underscores

This commit is contained in:
Ayaz Hafiz 2022-07-22 15:58:27 -04:00
parent 3e82d30e89
commit fbd70c4031
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
4 changed files with 240 additions and 1 deletions

View File

@ -1519,7 +1519,7 @@ fn parse_expr_end<'a>(
) -> ParseResult<'a, Expr<'a>, EExpr<'a>> {
let parser = skip_first!(
crate::blankspace::check_indent(min_indent, EExpr::IndentEnd),
move |a, s| parse_loc_term(min_indent, options, a, s)
move |a, s| parse_loc_term_or_underscore(min_indent, options, a, s)
);
match parser.parse(arena, state.clone()) {

View File

@ -0,0 +1,231 @@
Defs(
Defs {
tags: [
Index(2147483648),
Index(2147483649),
Index(2147483650),
Index(2147483651),
Index(2147483652),
],
regions: [
@0-19,
@20-39,
@40-59,
@60-72,
@73-128,
],
space_before: [
Slice(start = 0, length = 0),
Slice(start = 0, length = 1),
Slice(start = 1, length = 1),
Slice(start = 2, length = 1),
Slice(start = 3, length = 1),
],
space_after: [
Slice(start = 0, length = 0),
Slice(start = 1, length = 0),
Slice(start = 2, length = 0),
Slice(start = 3, length = 0),
Slice(start = 4, length = 0),
],
spaces: [
Newline,
Newline,
Newline,
Newline,
],
type_defs: [],
value_defs: [
Body(
@0-4 Apply(
@0-4 Tag(
"Pair",
),
[
@5-6 Identifier(
"x",
),
@7-8 Underscore(
"",
),
],
),
@11-19 Apply(
@11-15 Tag(
"Pair",
),
[
@16-17 Num(
"0",
),
@18-19 Num(
"1",
),
],
Space,
),
),
Body(
@20-28 Apply(
@20-24 Tag(
"Pair",
),
[
@25-26 Underscore(
"",
),
@27-28 Identifier(
"y",
),
],
),
@31-39 Apply(
@31-35 Tag(
"Pair",
),
[
@36-37 Num(
"0",
),
@38-39 Num(
"1",
),
],
Space,
),
),
Body(
@40-48 Apply(
@40-44 Tag(
"Pair",
),
[
@45-46 Underscore(
"",
),
@47-48 Underscore(
"",
),
],
),
@51-59 Apply(
@51-55 Tag(
"Pair",
),
[
@56-57 Num(
"0",
),
@58-59 Num(
"1",
),
],
Space,
),
),
Body(
@60-61 Underscore(
"",
),
@64-72 Apply(
@64-68 Tag(
"Pair",
),
[
@69-70 Num(
"0",
),
@71-72 Num(
"1",
),
],
Space,
),
),
Body(
@73-98 Apply(
@73-77 Tag(
"Pair",
),
[
@79-87 Apply(
@79-83 Tag(
"Pair",
),
[
@84-85 Identifier(
"x",
),
@86-87 Underscore(
"",
),
],
),
@90-98 Apply(
@90-94 Tag(
"Pair",
),
[
@95-96 Underscore(
"",
),
@97-98 Identifier(
"y",
),
],
),
],
),
@102-128 Apply(
@102-106 Tag(
"Pair",
),
[
@108-116 ParensAround(
Apply(
@108-112 Tag(
"Pair",
),
[
@113-114 Num(
"0",
),
@115-116 Num(
"1",
),
],
Space,
),
),
@119-127 ParensAround(
Apply(
@119-123 Tag(
"Pair",
),
[
@124-125 Num(
"2",
),
@126-127 Num(
"3",
),
],
Space,
),
),
],
Space,
),
),
],
},
@130-131 SpaceBefore(
Num(
"0",
),
[
Newline,
Newline,
],
),
)

View File

@ -0,0 +1,7 @@
Pair x _ = Pair 0 1
Pair _ y = Pair 0 1
Pair _ _ = Pair 0 1
_ = Pair 0 1
Pair (Pair x _) (Pair _ y) = Pair (Pair 0 1) (Pair 2 3)
0

View File

@ -266,6 +266,7 @@ mod test_parse {
pass/unary_not_with_parens.expr,
pass/unary_not.expr,
pass/underscore_backpassing.expr,
pass/underscore_in_assignment_pattern.expr,
pass/var_else.expr,
pass/var_if.expr,
pass/var_is.expr,