From bbeeb113926ba117791f67d49487edb908bf8893 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 15 Oct 2020 11:22:02 +0200 Subject: syntax: allow consecutive case values Signed-off-by: Jo-Philipp Wich --- parser.y | 1 + tests/02_runtime/04_switch_case | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/parser.y b/parser.y index 481a6ea..1d5ccb1 100644 --- a/parser.y +++ b/parser.y @@ -185,6 +185,7 @@ switch_cases(A) ::= switch_cases(B) switch_case(C). { A = append_op(B, C); } switch_cases(A) ::= switch_case(B). { A = B; } switch_case(A) ::= T_CASE(B) exp(C) T_COLON stmts(D). { A = wrap_op(B, C, D); } +switch_case(A) ::= T_CASE(B) exp(C) T_COLON. { A = wrap_op(B, C); } switch_case(A) ::= T_DEFAULT(B) T_COLON stmts(C). { A = wrap_op(B, C); } args(A) ::= args(B) T_COMMA T_LABEL(C). { A = append_op(B, C); } diff --git a/tests/02_runtime/04_switch_case b/tests/02_runtime/04_switch_case index 2102ee5..d3f6c94 100644 --- a/tests/02_runtime/04_switch_case +++ b/tests/02_runtime/04_switch_case @@ -271,3 +271,29 @@ In test(), line 6, byte 7: print(test(1), "\n"); %} -- End -- + + +11. Ensure that consecutive cases values are properly handled. + +-- Expect stdout -- +three and four +-- End -- + +-- Testcase -- +{% + switch (3) { + case 1: + case 2: + print("one and two\n"); + break; + + case 3: + case 4: + print("three and four\n"); + break; + + default: + print("five\n"); + } +%} +-- End -- -- cgit v1.2.3