ANTLRErrorStrategy

The interface for defining strategies to deal with syntax errors encountered during a parse by ANTLR-generated parsers. We distinguish between three different kinds of errors:

<ul> <li>The parser could not figure out which path to take in the ATN (none of the available alternatives could possibly match)</li> <li>The current input does not match what we were looking for</li> <li>A predicate evaluated to false</li> </ul>

Implementations of this interface report syntax errors by calling {@link Parser#notifyErrorListeners}.

<p>TODO: what to do about lexers</p>

Members

Functions

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)}.

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.

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.

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.

reportMatch
void reportMatch(Parser recognizer)

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

reset
void reset(Parser recognizer)

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

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}.

Meta