Skip to content

Commit

Permalink
Do not explore beyond rule stop states when computing possible next t…
Browse files Browse the repository at this point in the history
…okens during error recovery

Fixes tunnelvisionlabs#84
  • Loading branch information
br0nstein authored and daniellansun committed Nov 18, 2023
1 parent 79ce72f commit 0e8c76e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,5 @@ YYYY/MM/DD, github id, Full name, email
2020/10/16, adarshbhat, Adarsh Bhat, [email protected]
2020/10/20, adamwojs, Adam Wójs, adam[at]wojs.pl
2020/10/24, cliid, Jiwu Jang, [email protected]
2020/11/05, MichelHartmann, Michel Hartmann, [email protected]
2020/11/05, MichelHartmann, Michel Hartmann, [email protected]
2023/10/26, br0nstein, Aaron Braunstein, aa(last name)@gmail.com
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ TestTemplates ::= [
"NoViableAltAvoidance": [],
"TokenMismatch2": [],
"TokenMismatch3": [],
"TokenMismatch4": [],
"ExtraneousInput": []
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
TestType() ::= "Parser"

Options ::= [
"Debug": false
]

Grammar ::= [
"T": {<grammar("T")>}
]

Input() ::= "SELECT CONCAT() FROM tbl"

Rule() ::= "s"

Output() ::= <<
(selectStatement (selectQuery SELECT (expr (func CONCAT ( (expr )))) (fromClause FROM tbl)) limitOpt)
Error encountered: [@3,14:14=')',\<7>,1:14]<\n>
>>

Errors() ::= <<
line 1:14 mismatched input ')' expecting {IDENTIFIER, NUMBER}<\n>
>>

grammar(grammarName) ::= <<
grammar <grammarName>;

<ImportVisitor("T")>
<ErrorVisitor("T")>

s
@init {
<BuildParseTrees()>
}
@after {
<ToStringTree("$r.ctx"):writeln()>
<WalkVisitor("$ctx")>
}
: r=selectStatement ;
selectStatement : selectQuery limitOpt ;
selectQuery : 'SELECT' (expr | '*') fromClause? ;
limitOpt : ('LIMIT' NUMBER)? ;
expr : func | IDENTIFIER | NUMBER ;
fromClause : 'FROM' IDENTIFIER ;
func : IDENTIFIER '(' expr ',' expr (',' expr)* ')' ;
parenthesizedSelectQueryOrExpr : '(' (selectQuery limitOpt | expr) ')' ;
IDENTIFIER : [a-zA-Z]+ ;
NUMBER : [1-9][0-9]* ;
WS : [ \r\t\n]+ -> skip ;
>>
3 changes: 3 additions & 0 deletions runtime/Java/src/org/antlr/v4/runtime/atn/LL1Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ protected void _LOOK(@NotNull ATNState s,
calledRuleStack.set(s.ruleIndex);
}
}
if (!PredictionContext.isEmptyLocal(ctx)) {
return;
}
}

int n = s.getNumberOfTransitions();
Expand Down

0 comments on commit 0e8c76e

Please sign in to comment.