public interface ANTLRErrorStrategy
Parser.notifyErrorListeners(java.lang.String)
.
TODO: what to do about lexers
Modifier and Type | Method and Description |
---|---|
boolean |
inErrorRecoveryMode(Parser recognizer)
Tests whether or not
recognizer is in the process of recovering
from an error. |
void |
recover(Parser recognizer,
RecognitionException e)
This method is called to recover from exception
e . |
Token |
recoverInline(Parser recognizer)
This method is called when an unexpected symbol is encountered during an
inline match operation, such as
Parser.match(int) . |
void |
reportError(Parser recognizer,
RecognitionException e)
Report any kind of
RecognitionException . |
void |
reportMatch(Parser recognizer)
This method is called by when the parser successfully matches an input
symbol.
|
void |
reset(Parser recognizer)
Reset the error handler state for the specified
recognizer . |
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
RecognitionException . |
void reset(Parser recognizer)
recognizer
.recognizer
- the parser instanceToken recoverInline(Parser recognizer) throws RecognitionException
Parser.match(int)
. If the error
strategy successfully recovers from the match failure, this method
returns the Token
instance which should be treated as the
successful result of the match.
This method handles the consumption of any tokens - the caller should
not call Parser.consume()
after a successful recovery.
Note that the calling code will not report an error if this method
returns successfully. The error strategy implementation is responsible
for calling Parser.notifyErrorListeners(java.lang.String)
as appropriate.
recognizer
- the parser instanceRecognitionException
- if the error strategy was not able to
recover from the unexpected input symbolvoid recover(Parser recognizer, RecognitionException e) throws RecognitionException
e
. This method is
called after reportError(org.antlr.v4.runtime.Parser, org.antlr.v4.runtime.RecognitionException)
by the default exception handler
generated for a rule method.recognizer
- the parser instancee
- the recognition exception to recover fromRecognitionException
- if the error strategy could not recover from
the recognition exceptionreportError(org.antlr.v4.runtime.Parser, org.antlr.v4.runtime.RecognitionException)
void sync(Parser recognizer) throws RecognitionException
RecognitionException
.
The generated code currently contains calls to sync(org.antlr.v4.runtime.Parser)
after
entering the decision state of a closure block ((...)*
or
(...)+
).
For an implementation based on Jim Idle's "magic sync" mechanism, see
DefaultErrorStrategy.sync(org.antlr.v4.runtime.Parser)
.
recognizer
- the parser instanceRecognitionException
- if an error is detected by the error
strategy but cannot be automatically recovered at the current state in
the parsing processDefaultErrorStrategy.sync(org.antlr.v4.runtime.Parser)
boolean inErrorRecoveryMode(Parser recognizer)
recognizer
is in the process of recovering
from an error. In error recovery mode, Parser.consume()
adds
symbols to the parse tree by calling
ParserRuleContext.addErrorNode(Token)
instead of
ParserRuleContext.addChild(Token)
.recognizer
- the parser instancetrue
if the parser is currently recovering from a parse
error, otherwise false
void reportMatch(Parser recognizer)
recognizer
- the parser instancevoid reportError(Parser recognizer, RecognitionException e)
RecognitionException
. This method is called by
the default exception handler generated for a rule method.recognizer
- the parser instancee
- the recognition exception to report