From: Jukka-Pekka Iivonen Date: Fri, 26 Mar 2010 14:12:00 +0000 (+0100) Subject: parser: Accept comma-separated list in case-statements of switchs X-Git-Tag: 0.39.3~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a1d042d969a93393bf9a7064c943ccd0ec00fc1;p=thirdparty%2Fvala.git 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 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index efc54d317..eb009127e 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 000000000..28f37f3de --- /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 59b4d5f29..ec5e34e82 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)));