Skip to content

Commit

Permalink
fix: comma in _match_pattern_record and _match_pattern_list (#176)
Browse files Browse the repository at this point in the history
This PR fixes parsing error caused by comma in `_match_pattern_record`:

<img width="551" alt="image"
src="https://github.com/user-attachments/assets/56d5efed-b766-44a0-80d6-5dba9a3a7d65"
/>

as well as the extra item of anonymous comma in `_match_pattern_list`:

<img width="552" alt="image"
src="https://github.com/user-attachments/assets/ebf442ea-20fe-4077-8071-5b99f7863ae4"
/>

also renamed `item` into `entry` to align with `list_body`
  • Loading branch information
blindFS authored Dec 28, 2024
1 parent 755efd5 commit 249c39d
Show file tree
Hide file tree
Showing 5 changed files with 252,740 additions and 253,727 deletions.
19 changes: 8 additions & 11 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module.exports = grammar({
[$._block_body, $.val_closure],
[$._expression_parenthesized, $._expr_binary_expression_parenthesized],
[$._match_pattern_list, $.val_list],
[$._match_pattern_record, $._value],
[$._match_pattern_record, $.val_record],
[$._match_pattern_record_variable, $._value],
[$._match_pattern_value, $._value],
[$._parenthesized_body],
[$.block, $.val_closure],
Expand Down Expand Up @@ -482,15 +482,15 @@ module.exports = grammar({
seq(
BRACK().open_brack,
repeat(
field(
"item",
seq(
seq(
field(
"entry",
choice(
$._match_pattern_expression,
alias($._unquoted_in_list, $.val_string),
),
optional(PUNC().comma),
),
optional(PUNC().comma),
),
),
optional(
Expand All @@ -515,18 +515,15 @@ module.exports = grammar({
seq(
BRACK().open_brace,
repeat(
field(
"entry",
choice($.record_entry, $._match_pattern_record_variable),
seq(
field("entry", choice($.record_entry, $.val_variable)),
optional(PUNC().comma),
),
),
BRACK().close_brace,
optional($.cell_path),
),

_match_pattern_record_variable: ($) =>
seq($.val_variable, optional(PUNC().comma)),

ctrl_try: _ctrl_try_rule(false),
ctrl_try_parenthesized: _ctrl_try_rule(true),

Expand Down
112 changes: 54 additions & 58 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4218,12 +4218,12 @@
{
"type": "REPEAT",
"content": {
"type": "FIELD",
"name": "item",
"content": {
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "entry",
"content": {
"type": "CHOICE",
"members": [
{
Expand All @@ -4240,21 +4240,21 @@
"value": "val_string"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
{
Expand Down Expand Up @@ -4328,21 +4328,38 @@
{
"type": "REPEAT",
"content": {
"type": "FIELD",
"name": "entry",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "record_entry"
},
{
"type": "SYMBOL",
"name": "_match_pattern_record_variable"
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "entry",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "record_entry"
},
{
"type": "SYMBOL",
"name": "val_variable"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
{
Expand All @@ -4363,27 +4380,6 @@
}
]
},
"_match_pattern_record_variable": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "val_variable"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
"ctrl_try": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -20255,11 +20251,11 @@
],
[
"_match_pattern_record",
"val_record"
"_value"
],
[
"_match_pattern_record_variable",
"_value"
"_match_pattern_record",
"val_record"
],
[
"_match_pattern_value",
Expand Down
10 changes: 1 addition & 9 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -4608,14 +4608,10 @@
"type": "val_list",
"named": true,
"fields": {
"item": {
"entry": {
"multiple": true,
"required": false,
"types": [
{
"type": ",",
"named": false
},
{
"type": "expr_parenthesized",
"named": true
Expand Down Expand Up @@ -4782,10 +4778,6 @@
"multiple": true,
"required": false,
"types": [
{
"type": ",",
"named": false
},
{
"type": "record_entry",
"named": true
Expand Down
Loading

0 comments on commit 249c39d

Please sign in to comment.