Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify enum_variant_pattern rule #44

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions corpus/patterns-extended.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ match {
(enum_pattern
(enum_variant_pattern
(enum_tag
(raw_enum_tag)))))))))
(raw_enum_tag))
(pattern_fun))))))))
(term
(uni_term
(infix_expr
Expand Down Expand Up @@ -174,8 +175,9 @@ match {
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(constant_pattern
(signed_num_literal))))))
(pattern_fun
(constant_pattern
(signed_num_literal)))))))
(last_field_pat
(field_pattern
(ident)
Expand All @@ -184,10 +186,11 @@ match {
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(constant_pattern
(static_string
(chunk_literal_single
(str_literal)))))))))))
(pattern_fun
(constant_pattern
(static_string
(chunk_literal_single
(str_literal))))))))))))
(term
(uni_term
(infix_expr
Expand Down Expand Up @@ -248,7 +251,8 @@ match {
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(ident))))
(pattern_fun
(ident)))))
(last_elem_pat
(pattern
(record_pattern
Expand Down Expand Up @@ -550,19 +554,22 @@ match {
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(ident))))
(pattern_fun
(ident)))))
(pattern_or_branch
(enum_pattern_parens
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(ident))))
(pattern_fun
(ident)))))
(pattern_or_branch
(enum_pattern_parens
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(ident)))))))
(pattern_fun
(ident))))))))
(term
(uni_term
(infix_expr
Expand Down
29 changes: 17 additions & 12 deletions corpus/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ let 'Foo ('Bar x) = 'Foo ('Bar std.array) in x
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(enum_pattern_parens
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(ident))))))
(pattern_fun
(enum_pattern_parens
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(pattern_fun
(ident))))))))
(term
(uni_term
(infix_expr
Expand Down Expand Up @@ -79,7 +81,8 @@ fun {x,y} {y,z} ('Foo e) 'Bar or 'Baz => x + y + z
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(ident))))
(pattern_fun
(ident)))))
(pattern_fun
(enum_pattern_parens
(enum_tag
Expand Down Expand Up @@ -179,7 +182,8 @@ match {
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(ident))))))))
(pattern_fun
(ident)))))))))
(term
(uni_term
(infix_expr
Expand Down Expand Up @@ -219,12 +223,13 @@ match {
(enum_variant_pattern
(enum_tag
(raw_enum_tag))
(record_pattern
(field_pattern
(ident))
(last_field_pat
(pattern_fun
(record_pattern
(field_pattern
(ident)))))))))))
(ident))
(last_field_pat
(field_pattern
(ident))))))))))))
(term
(uni_term
(infix_expr
Expand Down
8 changes: 4 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ module.exports = grammar({
// keyword used as an identifier in a pattern. This requires to either
// update the scanner or to play with token precedence, with is left for
// future work.
pattern: $ => patternF($, $.enum_pattern, $.or_pattern, $.ident),
pattern_fun: $ => patternF($, $.enum_pattern_parens, $.or_pattern_parens, $.ident),
pattern_or_branch: $ => pattern_dataF($, $.enum_pattern_parens, $.or_pattern_parens, $.ident_no_or),
pattern: $ => patternF($, $.enum_pattern, $.or_pattern),
pattern_fun: $ => patternF($, $.enum_pattern_parens, $.or_pattern_parens),
pattern_or_branch: $ => pattern_dataF($, $.enum_pattern_parens, $.or_pattern_parens),

constant_pattern: $ => choice(
$.signed_num_literal,
Expand Down Expand Up @@ -311,7 +311,7 @@ module.exports = grammar({

enum_variant_pattern: $ => seq(
field("tag", $.enum_tag),
field("pat", patternF($, $.enum_pattern_parens, $.or_pattern_parens)),
field("pat", $.pattern_fun),
),

enum_pattern_unparens: $ => choice(
Expand Down
72 changes: 2 additions & 70 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1443,76 +1443,8 @@
"type": "FIELD",
"name": "pat",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "alias",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "ident"
},
{
"type": "STRING",
"value": "@"
}
]
}
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "pat",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "record_pattern"
},
{
"type": "SYMBOL",
"name": "array_pattern"
},
{
"type": "SYMBOL",
"name": "constant_pattern"
},
{
"type": "SYMBOL",
"name": "enum_pattern_parens"
},
{
"type": "SYMBOL",
"name": "ident"
},
{
"type": "STRING",
"value": "_"
},
{
"type": "SYMBOL",
"name": "or_pattern_parens"
}
]
}
}
]
}
]
"type": "SYMBOL",
"name": "pattern_fun"
}
}
]
Expand Down
40 changes: 1 addition & 39 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,50 +478,12 @@
"type": "enum_variant_pattern",
"named": true,
"fields": {
"alias": {
"multiple": true,
"required": false,
"types": [
{
"type": "@",
"named": false
},
{
"type": "ident",
"named": true
}
]
},
"pat": {
"multiple": false,
"required": true,
"types": [
{
"type": "_",
"named": false
},
{
"type": "array_pattern",
"named": true
},
{
"type": "constant_pattern",
"named": true
},
{
"type": "enum_pattern_parens",
"named": true
},
{
"type": "ident",
"named": true
},
{
"type": "or_pattern_parens",
"named": true
},
{
"type": "record_pattern",
"type": "pattern_fun",
"named": true
}
]
Expand Down
Loading
Loading