summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-10-15 11:22:02 +0200
committerJo-Philipp Wich <jo@mein.io>2020-10-15 11:22:02 +0200
commitbbeeb113926ba117791f67d49487edb908bf8893 (patch)
tree443272668c9bd81e9e75d67285a30f23a121ffe7
parentce01a7fdc8d49977e3d46dab0615580f90c6525c (diff)
syntax: allow consecutive case values
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--parser.y1
-rw-r--r--tests/02_runtime/04_switch_case26
2 files changed, 27 insertions, 0 deletions
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 --