Skip to content

Commit

Permalink
parser: add case_body node for case statement
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbz64 committed Oct 24, 2023
1 parent bab28f0 commit f0d8350
Show file tree
Hide file tree
Showing 5 changed files with 14,320 additions and 14,278 deletions.
12 changes: 7 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ module.exports = grammar({
_case_terminator: ($) =>
choice($._block_terminator, seq(kw("END"), kw("CASE"), $._terminator)),

_case_body: ($) =>
_case_branch_body: ($) =>
choice(
$.do_block,
$.repeat_statement,
Expand All @@ -563,18 +563,20 @@ module.exports = grammar({
kw("WHEN"),
field("value", $._expression),
kw("THEN"),
field("body", $._case_body)
field("body", $._case_branch_body)
),
case_otherwise_branch: ($) =>
seq(kw("OTHERWISE"), field("body", $._case_body)),
seq(kw("OTHERWISE"), field("body", $._case_branch_body)),

case_body: ($) =>
seq(repeat1($.case_when_branch), optional($.case_otherwise_branch)),

case_statement: ($) =>
seq(
kw("CASE"),
$.identifier,
":",
repeat1($.case_when_branch),
optional($.case_otherwise_branch),
optional($.case_body),
$._case_terminator
),

Expand Down
39 changes: 28 additions & 11 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4036,7 +4036,7 @@
}
]
},
"_case_body": {
"_case_branch_body": {
"type": "CHOICE",
"members": [
{
Expand Down Expand Up @@ -4105,7 +4105,7 @@
"name": "body",
"content": {
"type": "SYMBOL",
"name": "_case_body"
"name": "_case_branch_body"
}
}
]
Expand Down Expand Up @@ -4134,11 +4134,35 @@
"name": "body",
"content": {
"type": "SYMBOL",
"name": "_case_body"
"name": "_case_branch_body"
}
}
]
},
"case_body": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "case_when_branch"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "case_otherwise_branch"
},
{
"type": "BLANK"
}
]
}
]
},
"case_statement": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -4166,19 +4190,12 @@
"type": "STRING",
"value": ":"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "case_when_branch"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "case_otherwise_branch"
"name": "case_body"
},
{
"type": "BLANK"
Expand Down
25 changes: 20 additions & 5 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,25 @@
]
}
},
{
"type": "case_body",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "case_otherwise_branch",
"named": true
},
{
"type": "case_when_branch",
"named": true
}
]
}
},
{
"type": "case_otherwise_branch",
"named": true,
Expand Down Expand Up @@ -511,11 +530,7 @@
"required": true,
"types": [
{
"type": "case_otherwise_branch",
"named": true
},
{
"type": "case_when_branch",
"type": "case_body",
"named": true
},
{
Expand Down
Loading

0 comments on commit f0d8350

Please sign in to comment.