Property | Type | Description | |
---|---|---|---|
errorRecoveryMode | bool | ||
lastErrorIndex | int | ||
lastErrorStates |
Method | Description | |
---|---|---|
InErrorRecoveryMode ( Parser recognizer ) : bool |
|
|
Recover ( Parser recognizer, |
The default implementation resynchronizes the parser by consuming tokens until we find one in the resynchronization set--loosely the set of tokens that can follow the current rule.
|
|
RecoverInline ( Parser recognizer ) : IToken |
The default implementation attempts to recover from the mismatched input by using single token insertion and deletion as described below. If the recovery attempt fails, this method throws an InputMismatchException . EXTRA TOKEN (single token deletion) This recovery strategy is implemented by SingleTokenDeletion(Parser) . MISSING TOKEN (single token insertion) If current token (at This recovery strategy is implemented by SingleTokenInsertion(Parser) . EXAMPLE For example, Input stat → expr → atomand it will be trying to match the ')' at this point in the derivation: => ID '=' '(' INT ')' ('+' atom)* ';' ^The attempt to match ')' will fail when it sees ';' and call RecoverInline(Parser) . To recover, it sees that LA(1)==';' is in the set of tokens that can follow the ')' token reference in rule atom . It can assume that you forgot the ')' .
|
|
ReportError ( Parser recognizer, |
The default implementation returns immediately if the handler is already in error recovery mode. Otherwise, it calls BeginErrorCondition(Parser) and dispatches the reporting task based on the runtime type of e according to the following table.
|
|
ReportMatch ( Parser recognizer ) : void |
The default implementation simply calls EndErrorCondition(Parser) .
|
|
Reset ( Parser recognizer ) : void |
The default implementation simply calls EndErrorCondition(Parser) to ensure that the handler is not in error recovery mode.
|
|
Sync ( Parser recognizer ) : void |
The default implementation of IAntlrErrorStrategy.Sync(Parser) makes 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 subrules/loops and each iteration. Implements Jim Idle's magic sync mechanism in closures and optional subrules. E.g., a : sync ( stuff sync )* ; sync : {consume to what can follow sync} ;At the start of a sub rule upon error, Sync(Parser) performs single token deletion, if possible. If it can't do that, it bails on the current rule and uses the default error recovery, which consumes until the resynchronization set of the current rule. If the sub rule is optional ( During loop iteration, it consumes until it sees a token that can start a sub rule or what follows loop. Yes, that is pretty aggressive. We opt to stay in the loop as long as possible. ORIGINS Previous versions of ANTLR did a poor job of their recovery within loops. A single mismatch token or missing token would force the parser to bail out of the entire rules surrounding the loop. So, for rule classDef : 'class' ID '{' member* '}'input with an extra token between members would force the parser to consume until it found the next class definition rather than the 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 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 { }.
|
Method | Description | |
---|---|---|
BeginErrorCondition ( Parser recognizer ) : void |
This method is called to enter error recovery mode when a recognition exception is reported. This method is called to enter error recovery mode when a recognition exception is reported. |
|
ConstructToken ( ITokenSource tokenSource, int expectedTokenType, string tokenText, IToken current ) : IToken | ||
ConsumeUntil ( Parser recognizer, |
Consume tokens until one matches the given token set. Consume tokens until one matches the given token set. |
|
EndErrorCondition ( Parser recognizer ) : void |
This method is called to leave error recovery mode after recovering from a recognition exception. This method is called to leave error recovery mode after recovering from a recognition exception. |
|
GetSymbolText ( IToken symbol ) : string | ||
GetSymbolType ( IToken symbol ) : int | ||
GetTokenErrorDisplay ( IToken t ) : string |
How should a token be displayed in an error message? The default is to display just the text, but during development you might want to have a lot of information spit out. How should a token be displayed in an error message? The default is to display just the text, but during development you might want to have a lot of information spit out. Override in that case to use t.toString() (which, for CommonToken, dumps everything about the token). This is better than forcing you to override a method in your token objects because you don't have to go modify your lexer so that it creates a new Java type. |
|
NotifyErrorListeners ( Parser recognizer, string message, |
||
ReportFailedPredicate ( Parser recognizer, |
This is called by ReportError(Parser, RecognitionException) when the exception is a FailedPredicateException .
|
|
ReportInputMismatch ( Parser recognizer, |
This is called by ReportError(Parser, RecognitionException) when the exception is an InputMismatchException .
|
|
ReportMissingToken ( Parser recognizer ) : void |
This method is called to report a syntax error which requires the insertion of a missing token into the input stream. This method is called to report a syntax error which requires the insertion of a missing token into the input stream. At the time this method is called, the missing token has not yet been inserted. When this method returns, recognizer is in error recovery mode. This method is called when SingleTokenInsertion(Parser) identifies single-token insertion as a viable recovery strategy for a mismatched input error. The default implementation simply returns if the handler is already in error recovery mode. Otherwise, it calls BeginErrorCondition(Parser) to enter error recovery mode, followed by calling Parser.NotifyErrorListeners(string) . |
|
ReportNoViableAlternative ( Parser recognizer, |
This is called by ReportError(Parser, RecognitionException) when the exception is a NoViableAltException .
|
|
ReportUnwantedToken ( Parser recognizer ) : void |
This method is called to report a syntax error which requires the removal of a token from the input stream. This method is called to report a syntax error which requires the removal of a token from the input stream. At the time this method is called, the erroneous symbol is current This method is called when SingleTokenDeletion(Parser) identifies single-token deletion as a viable recovery strategy for a mismatched input error. The default implementation simply returns if the handler is already in error recovery mode. Otherwise, it calls BeginErrorCondition(Parser) to enter error recovery mode, followed by calling Parser.NotifyErrorListeners(string) . |
|
SingleTokenInsertion ( Parser recognizer ) : bool |
This method implements the single-token insertion inline error recovery strategy. This method implements the single-token insertion inline error recovery strategy. It is called by RecoverInline(Parser) if the single-token deletion strategy fails to recover from the mismatched input. If this method returns This method determines whether or not single-token insertion is viable by checking if the |
Method | Description | |
---|---|---|
EscapeWSAndQuote ( string s ) : string | ||
GetErrorRecoverySet ( Parser recognizer ) : |
||
GetExpectedTokens ( Parser recognizer ) : |
||
GetMissingSymbol ( Parser recognizer ) : IToken | ||
SingleTokenDeletion ( Parser recognizer ) : IToken |
protected BeginErrorCondition ( Parser recognizer ) : void | ||
recognizer | Parser | the parser instance |
return | void |
protected ConstructToken ( ITokenSource tokenSource, int expectedTokenType, string tokenText, IToken current ) : IToken | ||
tokenSource | ITokenSource | |
expectedTokenType | int | |
tokenText | string | |
current | IToken | |
return | IToken |
protected ConsumeUntil ( Parser recognizer, |
||
recognizer | Parser | |
set | ||
return | void |
protected EndErrorCondition ( Parser recognizer ) : void | ||
recognizer | Parser | |
return | void |
protected GetSymbolText ( IToken symbol ) : string | ||
symbol | IToken | |
return | string |
protected GetSymbolType ( IToken symbol ) : int | ||
symbol | IToken | |
return | int |
protected GetTokenErrorDisplay ( IToken t ) : string | ||
t | IToken | |
return | string |
public InErrorRecoveryMode ( Parser recognizer ) : bool | ||
recognizer | Parser | |
return | bool |
protected NotifyErrorListeners ( Parser recognizer, string message, |
||
recognizer | Parser | |
message | string | |
e | ||
return | void |
public Recover ( Parser recognizer, |
||
recognizer | Parser | |
e | ||
return | void |
public RecoverInline ( Parser recognizer ) : IToken | ||
recognizer | Parser | |
return | IToken |
public ReportError ( Parser recognizer, |
||
recognizer | Parser | |
e | ||
return | void |
protected ReportFailedPredicate ( Parser recognizer, |
||
recognizer | Parser | the parser instance |
e | the recognition exception | |
return | void |
protected ReportInputMismatch ( Parser recognizer, |
||
recognizer | Parser | the parser instance |
e | the recognition exception | |
return | void |
public ReportMatch ( Parser recognizer ) : void | ||
recognizer | Parser | |
return | void |
protected ReportMissingToken ( Parser recognizer ) : void | ||
recognizer | Parser | the parser instance |
return | void |
protected ReportNoViableAlternative ( Parser recognizer, |
||
recognizer | Parser | the parser instance |
e | the recognition exception | |
return | void |
protected ReportUnwantedToken ( Parser recognizer ) : void | ||
recognizer | Parser | the parser instance |
return | void |
protected SingleTokenInsertion ( Parser recognizer ) : bool | ||
recognizer | Parser | the parser instance |
return | bool |