Top Description Fields Constructors Methods
org.antlr.v4.runtime

public Class BailErrorStrategy

extends DefaultErrorStrategy
Class Inheritance
Imports
org.antlr.v4.runtime.misc.ParseCancellationException

This implementation of 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.

myparser.setErrorHandler(new BailErrorStrategy());

See Also
Parser#setErrorHandler(ANTLRErrorStrategy)

Field Summary

Inherited from org.antlr.v4.runtime.DefaultErrorStrategy:
errorRecoveryModelastErrorIndexlastErrorStatesnextTokensContextnextTokensState

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
recover(Parser
the parser instance
recognizer
,
RecognitionException
the recognition exception to recover from
e
)

Overrides org.antlr.v4.runtime.DefaultErrorStrategy.recover.

Implements org.antlr.v4.runtime.ANTLRErrorStrategy.recover.

Instead of recovering from exception e, re-throw it wrapped in a ParseCancellationException so it is not caught by the rule function catches.
public Token
recoverInline(Parser
the parser instance
recognizer
)

Overrides org.antlr.v4.runtime.DefaultErrorStrategy.recoverInline.

Implements org.antlr.v4.runtime.ANTLRErrorStrategy.recoverInline.

Make sure we don't attempt to recover inline; if the parser successfully recovers, it won't throw an exception.
public void
sync(Parser
the parser instance
recognizer
)

Overrides org.antlr.v4.runtime.DefaultErrorStrategy.sync.

Implements org.antlr.v4.runtime.ANTLRErrorStrategy.sync.

Make sure we don't attempt to recover from problems in subrules.
Inherited from org.antlr.v4.runtime.DefaultErrorStrategy:
beginErrorConditionconsumeUntilendErrorConditionescapeWSAndQuotegetErrorRecoverySetgetExpectedTokensgetMissingSymbolgetSymbolTextgetSymbolTypegetTokenErrorDisplayinErrorRecoveryModereportErrorreportFailedPredicatereportInputMismatchreportMatchreportMissingTokenreportNoViableAlternativereportUnwantedTokenresetsingleTokenDeletionsingleTokenInsertion

Constructor Detail

BailErrorStrategyback to summary
public BailErrorStrategy()

Method Detail

recoverback to summary
public void recover(Parser recognizer, RecognitionException e)

Overrides org.antlr.v4.runtime.DefaultErrorStrategy.recover.

Implements org.antlr.v4.runtime.ANTLRErrorStrategy.recover.

Instead of recovering from exception e, re-throw it wrapped in a ParseCancellationException so it is not caught by the rule function catches. Use Exception#getCause() to get the original RecognitionException.

Parameters
recognizer:Parser

Doc from org.antlr.v4.runtime.ANTLRErrorStrategy.recover.

the parser instance

e:RecognitionException

Doc from org.antlr.v4.runtime.ANTLRErrorStrategy.recover.

the recognition exception to recover from

Annotations
@Override
recoverInlineback to summary
public Token recoverInline(Parser recognizer) throws RecognitionException

Overrides org.antlr.v4.runtime.DefaultErrorStrategy.recoverInline.

Implements org.antlr.v4.runtime.ANTLRErrorStrategy.recoverInline.

Make sure we don't attempt to recover inline; if the parser successfully recovers, it won't throw an exception.

Parameters
recognizer:Parser

Doc from org.antlr.v4.runtime.ANTLRErrorStrategy.recoverInline.

the parser instance

Annotations
@Override
Exceptions
RecognitionException:

Doc from org.antlr.v4.runtime.ANTLRErrorStrategy.recoverInline.

if the error strategy was not able to recover from the unexpected input symbol

syncback to summary
public void sync(Parser recognizer)

Overrides org.antlr.v4.runtime.DefaultErrorStrategy.sync.

Implements org.antlr.v4.runtime.ANTLRErrorStrategy.sync.

Make sure we don't attempt to recover from problems in subrules.

Parameters
recognizer:Parser

Doc from org.antlr.v4.runtime.ANTLRErrorStrategy.sync.

the parser instance

Annotations
@Override