forked from jasder/antlr
_errHandler.sync(this);
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9176]
This commit is contained in:
parent
39314b8d74
commit
4920bb2c9e
|
@ -54,7 +54,7 @@ public interface ANTLRErrorStrategy {
|
|||
|
||||
/** Make sure that the current lookahead symbol is consistent with
|
||||
* what were expecting at this point in the ATN. You can call this
|
||||
* anytime but ANTLR only generates code to check before loops
|
||||
* anytime but ANTLR only generates code to check before subrules/loops
|
||||
* and each iteration.
|
||||
*
|
||||
* Implements Jim Idle's magic sync mechanism in closures and optional
|
||||
|
@ -74,7 +74,7 @@ public interface ANTLRErrorStrategy {
|
|||
* next member definition of the current class.
|
||||
*
|
||||
* This functionality cost a little bit of effort because the parser
|
||||
* has to compare token set at the start of the loop and add each
|
||||
* has to compare token set at the start of the loop and at each
|
||||
* iteration. If for some reason speed is suffering for you, you can
|
||||
* turn off this functionality by simply overriding this method as
|
||||
* a blank { }.
|
||||
|
|
|
@ -29,9 +29,7 @@
|
|||
|
||||
package org.antlr.v4.runtime;
|
||||
|
||||
import org.antlr.v4.runtime.atn.ATN;
|
||||
import org.antlr.v4.runtime.atn.ATNState;
|
||||
import org.antlr.v4.runtime.atn.RuleTransition;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||
|
||||
/** This is the default error handling mechanism for ANTLR parsers
|
||||
|
@ -131,9 +129,13 @@ public class DefaultANTLRErrorStrategy implements ANTLRErrorStrategy {
|
|||
|
||||
/** Make sure that the current lookahead symbol is consistent with
|
||||
* what were expecting at this point in the ATN.
|
||||
*
|
||||
* TODO: see if we can merge sync() and recoverInline(). are they same?
|
||||
* does one call the other?
|
||||
* sync() differs fundamentally from the recoverInline() method.
|
||||
* In this case, we throw out a token that's not in the set of what
|
||||
* were expecting at this point. recoverInline() only deletes this
|
||||
* token if LT(2) (token after the current token) is what were expecting;
|
||||
* i.e., we have an extra token sitting on the input stream. sync()
|
||||
* simply consumes until it finds something that can start whatever
|
||||
* follows the call to sync().
|
||||
*/
|
||||
@Override
|
||||
public void sync(BaseRecognizer recognizer) {
|
||||
|
|
|
@ -219,6 +219,7 @@ CodeBlockForAlt(c, locals, preamble, ops) ::= <<
|
|||
|
||||
LL1AltBlock(choice, preamble, alts, error) ::= <<
|
||||
setState(<choice.stateNumber>);
|
||||
_errHandler.sync(this);
|
||||
<if(choice.label)><labelref(choice.label)> = _input.LT(1);<endif>
|
||||
<preamble; separator="\n">
|
||||
switch ( _input.LA(1) ) {
|
||||
|
@ -232,6 +233,7 @@ switch ( _input.LA(1) ) {
|
|||
|
||||
LL1OptionalBlock(choice, alts, error) ::= <<
|
||||
setState(<choice.stateNumber>);
|
||||
_errHandler.sync(this);
|
||||
switch ( _input.LA(1) ) {
|
||||
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
||||
<alt>
|
||||
|
@ -243,6 +245,7 @@ switch ( _input.LA(1) ) {
|
|||
|
||||
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= <<
|
||||
setState(<choice.stateNumber>);
|
||||
_errHandler.sync(this);
|
||||
<preamble; separator="\n">
|
||||
if ( <expr> ) {
|
||||
<alts; separator="\n">
|
||||
|
@ -312,6 +315,7 @@ do {
|
|||
|
||||
AltBlock(choice, preamble, alts, error) ::= <<
|
||||
setState(<choice.stateNumber>);
|
||||
_errHandler.sync(this);
|
||||
<if(choice.label)><labelref(choice.label)> = _input.LT(1);<endif>
|
||||
<preamble; separator="\n">
|
||||
switch ( _interp.adaptivePredict(_input,<choice.decision>,_ctx) ) {
|
||||
|
@ -324,6 +328,7 @@ case <i>:
|
|||
|
||||
OptionalBlock(choice, alts, error) ::= <<
|
||||
setState(<choice.stateNumber>);
|
||||
_errHandler.sync(this);
|
||||
switch ( _interp.adaptivePredict(_input,<choice.decision>,_ctx) ) {
|
||||
<alts:{alt |
|
||||
case <i>:
|
||||
|
|
Loading…
Reference in New Issue