[vala/wip/issue/987] parser: Avoid mitigation for missing token if it follows DOT or DOUBLE_COLON
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/987] parser: Avoid mitigation for missing token if it follows DOT or DOUBLE_COLON
- Date: Tue, 16 Jun 2020 13:02:00 +0000 (UTC)
commit aca11ebb702d67e641fd52f5c012749e2949297e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Jun 16 14:55:04 2020 +0200
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]