From: Rico Tzschichholz Date: Thu, 5 Jan 2017 11:17:21 +0000 (+0100) Subject: genieparser: Allow comma-separated identifiers in definition of enums X-Git-Tag: 0.35.6~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4672f73d4679444a3c93f6188687e899c5c2827b;p=thirdparty%2Fvala.git genieparser: Allow comma-separated identifiers in definition of enums https://bugzilla.gnome.org/show_bug.cgi?id=776833 --- diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index a72dead84..df4f66e9b 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -124,6 +124,14 @@ public class Vala.Genie.Parser : CodeVisitor { return false; } + inline bool accept_separator () { + if (current () == TokenType.COMMA || current () == TokenType.EOL) { + next (); + return true; + } + return false; + } + inline bool accept_terminator () { if (current () == TokenType.SEMICOLON || current () == TokenType.EOL) { next (); @@ -165,6 +173,16 @@ public class Vala.Genie.Parser : CodeVisitor { throw new ParseError.SYNTAX ("expected %s but got %s with previous %s", type.to_string (), cur.to_string (), pre.to_string()); } + inline bool expect_separator () throws ParseError { + if (accept_separator ()) { + return true; + } + + TokenType cur = current (); + + throw new ParseError.SYNTAX ("expected line end or comma but got %s", cur.to_string()); + } + inline bool expect_terminator () throws ParseError { if (accept_terminator ()) { return true; @@ -318,8 +336,10 @@ public class Vala.Genie.Parser : CodeVisitor { } break; default: - throw new ParseError.SYNTAX ("expected identifier"); - } + break; + } + + throw new ParseError.SYNTAX ("expected identifier"); } string parse_identifier () throws ParseError { @@ -3452,7 +3472,9 @@ public class Vala.Genie.Parser : CodeVisitor { set_attributes (ev, value_attrs); en.add_value (ev); - expect (TokenType.EOL); + if (expect_separator ()) { + accept (TokenType.EOL); + } } while (true); expect (TokenType.DEDENT);