]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: Avoid mitigation for missing token if it follows DOT or DOUBLE_COLON 8edd90dd26e3acf652ea4a24e288d7f9a57a5cb4 128/head
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 16 Jun 2020 12:55:04 +0000 (14:55 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 20 Jun 2020 06:46:41 +0000 (08:46 +0200)
Rolling back to a DOT/DOUBLE_COLON token will retrigger the attempt to parse
an incomplete member access.

Regression of 4368a4fa667148378dcdbd251a4ae4e00c9a8e5a

Fixes https://gitlab.gnome.org/GNOME/vala/issues/987

vala/valaparser.vala

index 191bc75d55d8e445a34c4ea907a3a8c19f7cd211..3adc6e71a885cecec7583740be1283ccdcb1a63c 100644 (file)
@@ -104,10 +104,25 @@ public class Vala.Parser : CodeVisitor {
                assert (size <= BUFFER_SIZE);
        }
 
+       inline void safe_prev () {
+               switch (previous ()) {
+               case TokenType.DOT:
+               case TokenType.DOUBLE_COLON:
+                       break;
+               default:
+                       prev ();
+                       break;
+               }
+       }
+
        inline TokenType current () {
                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 ();
@@ -129,13 +144,13 @@ public class Vala.Parser : CodeVisitor {
 
                switch (type) {
                case TokenType.CLOSE_BRACE:
-                       prev ();
+                       safe_prev ();
                        report_parse_error (new ParseError.SYNTAX ("following block delimiter %s missing", type.to_string ()));
                        return true;
                case TokenType.CLOSE_BRACKET:
                case TokenType.CLOSE_PARENS:
                case TokenType.SEMICOLON:
-                       prev ();
+                       safe_prev ();
                        report_parse_error (new ParseError.SYNTAX ("following expression/statement delimiter %s missing", type.to_string ()));
                        return true;
                default:
@@ -1686,9 +1701,7 @@ public class Vala.Parser : CodeVisitor {
                try {
                        skip_type ();
                } catch (ParseError e) {
-                       prev ();
-                       var token = current ();
-                       next ();
+                       var token = previous ();
                        if (token == TokenType.DOT || token == TokenType.DOUBLE_COLON) {
                                rollback (begin);
                                return true;