DefaultErrorStrategy

This is the default implementation of {@link ANTLRErrorStrategy} used for error reporting and recovery in ANTLR parsers.

Members

Functions

beginErrorCondition
void beginErrorCondition(Parser recognizer)

This method is called to enter error recovery mode when a recognition exception is reported.

consumeUntil
void consumeUntil(Parser recognizer, IntervalSet set)

Consume tokens until one matches the given token set.

endErrorCondition
void endErrorCondition(Parser recognizer)

This method is called to leave error recovery mode after recovering from a recognition exception.

escapeWSAndQuote
string escapeWSAndQuote(string s)
Undocumented in source. Be warned that the author may not have intended to support it.
getErrorRecoverySet
IntervalSet getErrorRecoverySet(Parser recognizer)

Compute the error recovery set for the current rule. During rule invocation, the parser pushes the set of tokens that can follow that rule reference on the stack; this amounts to computing FIRST of what follows the rule reference in the enclosing rule. See LinearApproximator.FIRST(). This local follow set only includes tokens from within the rule; i.e., the FIRST computation done by ANTLR stops at the end of a rule.

getExpectedTokens
IntervalSet getExpectedTokens(Parser recognizer)
Undocumented in source. Be warned that the author may not have intended to support it.
getMissingSymbol
Token getMissingSymbol(Parser recognizer)

Conjure up a missing token during error recovery.

getSymbolText
string getSymbolText(Token symbol)
Undocumented in source. Be warned that the author may not have intended to support it.
getSymbolType
int getSymbolType(Token symbol)
Undocumented in source. Be warned that the author may not have intended to support it.
getTokenErrorDisplay
string getTokenErrorDisplay(Token t)

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.

inErrorRecoveryMode
bool inErrorRecoveryMode(Parser recognizer)
Undocumented in source. Be warned that the author may not have intended to support it.
recover
void recover(Parser recognizer, RecognitionException e)

{@inheritDoc}

recoverInline
Token recoverInline(Parser recognizer)

{@inheritDoc}

reportError
void reportError(Parser recognizer, RecognitionException e)

{@inheritDoc}

reportFailedPredicate
void reportFailedPredicate(Parser recognizer, FailedPredicateException e)

This is called by {@link #reportError} when the exception is a {@link FailedPredicateException}.

reportInputMismatch
void reportInputMismatch(Parser recognizer, InputMismatchException e)

This is called by {@link #reportError} when the exception is an {@link InputMismatchException}.

reportMatch
void reportMatch(Parser recognizer)

{@inheritDoc}

reportMissingToken
void reportMissingToken(Parser recognizer)

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, {@code recognizer} is in error recovery mode.

reportNoViableAlternative
void reportNoViableAlternative(Parser recognizer, NoViableAltException e)

This is called by {@link #reportError} when the exception is a {@link NoViableAltException}.

reportUnwantedToken
void reportUnwantedToken(Parser recognizer)

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 {@code LT(1)} symbol and has not yet been removed from the input stream. When this method returns, {@code recognizer} is in error recovery mode.

reset
void reset(Parser recognizer)

<p>The default implementation simply calls {@link #endErrorCondition} to ensure that the handler is not in error recovery mode.</p>

singleTokenDeletion
Token singleTokenDeletion(Parser recognizer)

This method implements the single-token deletion inline error recovery strategy. It is called by {@link #recoverInline} to attempt to recover from mismatched input. If this method returns null, the parser and error handler state will not have changed. If this method returns non-null, {@code recognizer} will <em>not</em> be in error recovery mode since the returned token was a successful match.

singleTokenInsertion
bool singleTokenInsertion(Parser recognizer)

This method implements the single-token insertion inline error recovery strategy. It is called by {@link #recoverInline} if the single-token deletion strategy fails to recover from the mismatched input. If this method returns {@code true}, {@code recognizer} will be in error recovery mode.

sync
void sync(Parser recognizer)

The default implementation of {@link ANTLRErrorStrategy#sync} 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.

Variables

errorRecoveryMode
bool errorRecoveryMode;

Indicates whether the error strategy is currently "recovering from an error". This is used to suppress reporting multiple error messages while attempting to recover from a detected syntax error.

lastErrorIndex
int lastErrorIndex;

The index into the input stream where the last error occurred. This is used to prevent infinite loops where an error is found but no token is consumed during recovery...another error is found, ad nauseum. This is a failsafe mechanism to guarantee that at least one token/tree node is consumed for two errors.

lastErrorStates
IntervalSet lastErrorStates;
Undocumented in source.
nextTokensContext
ParserRuleContext nextTokensContext;

This field is used to propagate information about the lookahead following the previous match. Since prediction prefers completing the current rule to error recovery efforts, error reporting may occur later than the original point where it was discoverable. The original context is used to compute the true expected sets as though the reporting occurred as early as possible.

nextTokensState
int nextTokensState;

@see #nextTokensContext

Inherited Members

From ANTLRErrorStrategy

reset
void reset(Parser recognizer)

Reset the error handler state for the specified {@code recognizer}. @param recognizer the parser instance

recoverInline
Token recoverInline(Parser recognizer)

This method is called when an unexpected symbol is encountered during an inline match operation, such as {@link Parser#match}. If the error strategy successfully recovers from the match failure, this method returns the {@link Token} instance which should be treated as the successful result of the match.

recover
void recover(Parser recognizer, RecognitionException e)

This method is called to recover from exception {@code e}. This method is called after {@link #reportError} by the default exception handler generated for a rule method.

sync
void sync(Parser recognizer)

This method provides the error handler with an opportunity to handle syntactic or semantic errors in the input stream before they result in a {@link RecognitionException}.

inErrorRecoveryMode
bool inErrorRecoveryMode(Parser recognizer)

Tests whether or not {@code recognizer} is in the process of recovering from an error. In error recovery mode, {@link Parser#consume} adds symbols to the parse tree by calling {@link ParserRuleContext#addErrorNode(Token)} instead of {@link ParserRuleContext#addChild(Token)}.

reportMatch
void reportMatch(Parser recognizer)

This method is called by when the parser successfully matches an input symbol.

reportError
void reportError(Parser recognizer, RecognitionException e)

Report any kind of {@link RecognitionException}. This method is called by the default exception handler generated for a rule method.

Meta