Skip to content

Commit

Permalink
Fix coments in switch body
Browse files Browse the repository at this point in the history
  • Loading branch information
Beaglefoot committed Nov 5, 2023
1 parent 90c8d9b commit 6fdea72
Show file tree
Hide file tree
Showing 5 changed files with 46,577 additions and 46,296 deletions.
16 changes: 9 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,17 @@ module.exports = grammar({

switch_statement: $ => seq('switch', '(', $._exp, ')', repeat($.comment), $.switch_body),

switch_body: $ => seq('{', repeat(choice($.switch_case, $.switch_default)), '}'),
switch_body: $ => seq('{', repeat(choice($.switch_case, $.switch_default, $.comment)), '}'),

switch_case: $ =>
seq(
'case',
field('value', choice($._primitive, $.regex)),
':',
repeat($.comment),
optional($._statement)
prec.right(
seq(
'case',
field('value', choice($._primitive, $.regex)),
':',
repeat($.comment),
optional($._statement)
)
),

switch_default: $ => seq('default', ':', repeat($.comment), $._statement),
Expand Down
84 changes: 46 additions & 38 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,10 @@
{
"type": "SYMBOL",
"name": "switch_default"
},
{
"type": "SYMBOL",
"name": "comment"
}
]
}
Expand All @@ -838,53 +842,57 @@
]
},
"switch_case": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "case"
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "case"
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_primitive"
},
{
"type": "SYMBOL",
"name": "regex"
}
]
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "comment"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_primitive"
"name": "_statement"
},
{
"type": "SYMBOL",
"name": "regex"
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "comment"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_statement"
},
{
"type": "BLANK"
}
]
}
]
]
}
},
"switch_default": {
"type": "SEQ",
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -3831,6 +3831,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "comment",
"named": true
},
{
"type": "switch_case",
"named": true
Expand Down
Loading

0 comments on commit 6fdea72

Please sign in to comment.