From 8edd90dd26e3acf652ea4a24e288d7f9a57a5cb4 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Tue, 16 Jun 2020 14:55:04 +0200 Subject: [PATCH] parser: Avoid mitigation for missing token if it follows DOT or DOUBLE_COLON 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 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 191bc75d5..3adc6e71a 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -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; -- 2.47.2