Skip to content

Commit

Permalink
Merge pull request #226 from stsewd/match-block-node
Browse files Browse the repository at this point in the history
feat: put the inner match block in a `block` rule
  • Loading branch information
amaanq committed Jul 12, 2023
2 parents 5a5455e + 43d12ec commit 538a532
Show file tree
Hide file tree
Showing 5 changed files with 53,535 additions and 57,251 deletions.
12 changes: 11 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,17 @@ module.exports = grammar({
commaSep1(field('subject', $.expression)),
optional(','),
':',
repeat(field('alternative', $.case_clause))),
field('body', alias($._match_block, $.block)),
),

_match_block: $ => choice(
seq(
$._indent,
repeat(field('alternative', $.case_clause)),
$._dedent,
),
$._newline,
),

case_clause: $ => seq(
'case',
Expand Down
45 changes: 40 additions & 5 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -959,18 +959,53 @@
"value": ":"
},
{
"type": "REPEAT",
"type": "FIELD",
"name": "body",
"content": {
"type": "FIELD",
"name": "alternative",
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "case_clause"
}
"name": "_match_block"
},
"named": true,
"value": "block"
}
}
]
},
"_match_block": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_indent"
},
{
"type": "REPEAT",
"content": {
"type": "FIELD",
"name": "alternative",
"content": {
"type": "SYMBOL",
"name": "case_clause"
}
}
},
{
"type": "SYMBOL",
"name": "_dedent"
}
]
},
{
"type": "SYMBOL",
"name": "_newline"
}
]
},
"case_clause": {
"type": "SEQ",
"members": [
Expand Down
21 changes: 16 additions & 5 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,18 @@
{
"type": "block",
"named": true,
"fields": {},
"fields": {
"alternative": {
"multiple": true,
"required": false,
"types": [
{
"type": "case_clause",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": false,
Expand Down Expand Up @@ -1991,12 +2002,12 @@
"type": "match_statement",
"named": true,
"fields": {
"alternative": {
"multiple": true,
"required": false,
"body": {
"multiple": false,
"required": true,
"types": [
{
"type": "case_clause",
"type": "block",
"named": true
}
]
Expand Down
Loading

0 comments on commit 538a532

Please sign in to comment.