Skip to content

Commit

Permalink
parser: add or when to case_statement
Browse files Browse the repository at this point in the history
Fixes #68
  • Loading branch information
jkbz64 committed Sep 13, 2024
1 parent a87b98d commit f7914bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
13 changes: 6 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,15 +895,14 @@ module.exports = grammar({
_case_terminator: ($) =>
choice($._block_terminator, seq(kw("END"), kw("CASE"), $._terminator)),

_case_branch_body: ($) => choice($.do_block, $._terminated_statement),
_case_branch_body: ($) =>
choice($.do_block, field("statement", $._terminated_statement)),

case_conditon: ($) =>
seq(optional(seq(kw("OR"), kw("WHEN"))), $._expression),

case_when_branch: ($) =>
seq(
kw("WHEN"),
field("condition", $._expression),
kw("THEN"),
$._case_branch_body
),
seq(kw("WHEN"), repeat($.case_conditon), kw("THEN"), $._case_branch_body),
case_otherwise_branch: ($) => seq(kw("OTHERWISE"), $._case_branch_body),

case_body: ($) =>
Expand Down
18 changes: 16 additions & 2 deletions test/corpus/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ CASE test:
x = 5.
y = 20.
END.
WHEN "yyy" OR WHEN "zxc" THEN y = 3.
WHEN "def" THEN y = 10.
OTHERWISE c = 8.
END CASE.
Expand All @@ -1606,7 +1607,8 @@ END CASE.
(identifier)
(body
(case_when_branch
(double_quoted_string)
(case_conditon
(double_quoted_string))
(do_block
(body
(variable_assignment
Expand All @@ -1618,7 +1620,19 @@ END CASE.
(identifier)
(number_literal))))))
(case_when_branch
(double_quoted_string)
(case_conditon
(logical_expression
(double_quoted_string)
(identifier)))
(case_conditon
(double_quoted_string))
(variable_assignment
(assignment
(identifier)
(number_literal))))
(case_when_branch
(case_conditon
(double_quoted_string))
(variable_assignment
(assignment
(identifier)
Expand Down

0 comments on commit f7914bb

Please sign in to comment.