[vala/staging: 1/12] parser: Accept comma-separated list in case-statements of switchs
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 1/12] parser: Accept comma-separated list in case-statements of switchs
- Date: Fri, 15 Dec 2017 08:23:22 +0000 (UTC)
commit 1a1d042d969a93393bf9a7064c943ccd0ec00fc1
Author: Jukka-Pekka Iivonen <jp0409 jippii fi>
Date: Fri Mar 26 15:12:00 2010 +0100
parser: Accept comma-separated list in case-statements of switchs
switch (i) {
case 0, 1, 2:
break;
}
https://bugzilla.gnome.org/show_bug.cgi?id=614015
tests/Makefile.am | 1 +
tests/parser/switch-statement.vala | 13 +++++++++++++
vala/valaparser.vala | 4 ++++
3 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index efc54d3..eb00912 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -315,6 +315,7 @@ TESTS = \
annotations/deprecated.vala \
annotations/description.vala \
annotations/noaccessormethod.test \
+ parser/switch-statement.vala \
$(NULL)
NON_NULL_TESTS = \
diff --git a/tests/parser/switch-statement.vala b/tests/parser/switch-statement.vala
new file mode 100644
index 0000000..28f37f3
--- /dev/null
+++ b/tests/parser/switch-statement.vala
@@ -0,0 +1,13 @@
+void case_with_list () {
+ int i = 1;
+ switch (i) {
+ case 0, 1, 2:
+ break;
+ default:
+ assert_not_reached ();
+ }
+}
+
+void main () {
+ case_with_list ();
+}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 59b4d5f..ec5e34e 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -1907,6 +1907,10 @@ public class Vala.Parser : CodeVisitor {
do {
if (accept (TokenType.CASE)) {
section.add_label (new SwitchLabel (parse_expression (), get_src
(begin)));
+ while (current () == TokenType.COMMA) {
+ expect (TokenType.COMMA);
+ section.add_label (new SwitchLabel (parse_expression (),
get_src (begin)));
+ }
} else {
expect (TokenType.DEFAULT);
section.add_label (new SwitchLabel.with_default (get_src (begin)));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]