public class BailErrorStrategy extends DefaultErrorStrategy
ANTLRErrorStrategy responds to syntax errors
by immediately canceling the parse operation with a
ParseCancellationException. The implementation ensures that the
ParserRuleContext.exception field is set for all parse tree nodes
that were not completed prior to encountering the error.
This error strategy is useful in the following scenarios.
sync(org.antlr.v4.runtime.Parser) improves the performance of
the first stage.BailErrorStrategy avoids wasting work on recovering from errors
when the result will be ignored either way.
myparser.setErrorHandler(new BailErrorStrategy());
errorRecoveryMode, lastErrorIndex, lastErrorStates| Constructor and Description |
|---|
BailErrorStrategy() |
| Modifier and Type | Method and Description |
|---|---|
void |
recover(Parser recognizer,
RecognitionException e)
Instead of recovering from exception
e, re-throw it wrapped
in a ParseCancellationException so it is not caught by the
rule function catches. |
Token |
recoverInline(Parser recognizer)
Make sure we don't attempt to recover inline; if the parser
successfully recovers, it won't throw an exception.
|
void |
sync(Parser recognizer)
Make sure we don't attempt to recover from problems in subrules.
|
beginErrorCondition, consumeUntil, endErrorCondition, escapeWSAndQuote, getErrorRecoverySet, getExpectedTokens, getMissingSymbol, getSymbolText, getSymbolType, getTokenErrorDisplay, inErrorRecoveryMode, reportError, reportFailedPredicate, reportInputMismatch, reportMatch, reportMissingToken, reportNoViableAlternative, reportUnwantedToken, reset, singleTokenDeletion, singleTokenInsertionpublic void recover(Parser recognizer, RecognitionException e)
e, re-throw it wrapped
in a ParseCancellationException so it is not caught by the
rule function catches. Use Throwable.getCause() to get the
original RecognitionException.recover in interface ANTLRErrorStrategyrecover in class DefaultErrorStrategyrecognizer - the parser instancee - the recognition exception to recover fromANTLRErrorStrategy.reportError(org.antlr.v4.runtime.Parser, org.antlr.v4.runtime.RecognitionException)public Token recoverInline(Parser recognizer) throws RecognitionException
recoverInline in interface ANTLRErrorStrategyrecoverInline in class DefaultErrorStrategyrecognizer - the parser instanceRecognitionException - if the error strategy was not able to
recover from the unexpected input symbolpublic void sync(Parser recognizer)
sync in interface ANTLRErrorStrategysync in class DefaultErrorStrategyrecognizer - the parser instanceDefaultErrorStrategy.sync(org.antlr.v4.runtime.Parser)