[vala/wip/issue/987] vala: Don't rollback for possible member-access inside of type-argument-list



commit e3fec82a23ab6cadc99a5384bff5c5d085ca8965
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun May 10 19:17:39 2020 +0200

    vala: Don't rollback for possible member-access inside of type-argument-list
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/987

 vala/valaparser.vala | 51 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 28 insertions(+), 23 deletions(-)
---
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 9f0b976fc..637ea36a0 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -108,6 +108,10 @@ public class Vala.Parser : CodeVisitor {
                return tokens[index].type;
        }
 
+       inline TokenType previous () {
+               return tokens[(index - 1 + BUFFER_SIZE) % BUFFER_SIZE].type;
+       }
+
        inline bool accept (TokenType type) {
                if (current () == type) {
                        next ();
@@ -414,6 +418,8 @@ public class Vala.Parser : CodeVisitor {
        }
 
        void skip_type () throws ParseError {
+               var begin = get_location ();
+
                accept (TokenType.DYNAMIC);
                accept (TokenType.OWNED);
                accept (TokenType.UNOWNED);
@@ -437,17 +443,27 @@ public class Vala.Parser : CodeVisitor {
                        accept (TokenType.INTERR);
                }
 
-               while (accept (TokenType.OPEN_BRACKET)) {
-                       do {
-                               // required for decision between expression and declaration statement
-                               if (current () != TokenType.COMMA && current () != TokenType.CLOSE_BRACKET) {
-                                       parse_expression ();
-                               }
-                       } while (accept (TokenType.COMMA));
-                       expect (TokenType.CLOSE_BRACKET);
-                       accept (TokenType.INTERR);
+               try {
+                       while (accept (TokenType.OPEN_BRACKET)) {
+                               do {
+                                       // required for decision between expression and declaration statement
+                                       if (current () != TokenType.COMMA && current () != 
TokenType.CLOSE_BRACKET) {
+                                               parse_expression ();
+                                       }
+                               } while (accept (TokenType.COMMA));
+                               expect (TokenType.CLOSE_BRACKET);
+                               accept (TokenType.INTERR);
+                       }
+                       accept (TokenType.OP_NEG);
+               } catch (ParseError e) {
+                       var token = previous ();
+                       // decide if this could be an incomplete member-access
+                       if (token == TokenType.DOT || token == TokenType.DOUBLE_COLON) {
+                               rollback (begin);
+                       } else {
+                               throw e;
+                       }
                }
-               accept (TokenType.OP_NEG);
        }
 
        bool is_inner_array_type () {
@@ -1666,19 +1682,7 @@ public class Vala.Parser : CodeVisitor {
                var begin = get_location ();
 
                // decide between declaration and expression statement
-               try {
-                       skip_type ();
-               } catch (ParseError e) {
-                       prev ();
-                       var token = current ();
-                       next ();
-                       if (token == TokenType.DOT || token == TokenType.DOUBLE_COLON) {
-                               rollback (begin);
-                               return true;
-                       } else {
-                               throw e;
-                       }
-               }
+               skip_type ();
                switch (current ()) {
                // invocation expression
                case TokenType.OPEN_PARENS:
@@ -1700,6 +1704,7 @@ public class Vala.Parser : CodeVisitor {
                case TokenType.OP_GT: // >>=
                // member access
                case TokenType.DOT:
+               case TokenType.DOUBLE_COLON:
                // pointer member access
                case TokenType.OP_PTR:
                // literal expression


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