[vala/wip/genie] genieparser: Allow comma-separated identifiers in definition of enums



commit 711412a48eef7494d9b6a70348469988e26b11c7
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Jan 5 12:17:21 2017 +0100

    genieparser: Allow comma-separated identifiers in definition of enums
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776833

 vala/valagenieparser.vala |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index a72dead..df4f66e 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]