Class DescriptiveErrorStrategy
- All Implemented Interfaces:
org.antlr.v4.runtime.ANTLRErrorStrategy
Cancels the parse with ParseCancellationException after reporting,
matching BailErrorStrategy. sync(org.antlr.v4.runtime.Parser) is a
no-op so the SLL stage of two-stage parsing stays cheap. Diagnostics are
emitted from recover(org.antlr.v4.runtime.Parser, org.antlr.v4.runtime.RecognitionException): after a failed SLL probe the strategy may still
be in ANTLR's internal recovery mode, which suppresses
DefaultErrorStrategy.reportError(org.antlr.v4.runtime.Parser, org.antlr.v4.runtime.RecognitionException), while recover still runs under LL.
For IDE multi-error collection use create(CharStream, boolean) with
recover == true, which selects
RecoveringDescriptiveErrorStrategy. Hosts should treat
ErrorCollector as the multi-error source
of truth: recovery may still produce a partial tree that fails later during
AST building.
-
Field Summary
Fields inherited from class org.antlr.v4.runtime.DefaultErrorStrategy
errorRecoveryMode, lastErrorIndex, lastErrorStates, nextTokensContext, nextTokensState -
Constructor Summary
ConstructorsConstructorDescriptionDescriptiveErrorStrategy(org.antlr.v4.runtime.CharStream charStream) Fail-fast strategy with friendly diagnostics. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.antlr.v4.runtime.ANTLRErrorStrategycreate(org.antlr.v4.runtime.CharStream charStream, boolean recover) Select fail-fast or recovering strategy.protected StringcreateFailedPredicateErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.FailedPredicateException e) Format a failed-predicate diagnostic.protected StringcreateInputMismatchErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.InputMismatchException e) protected StringcreateNoViableAlternativeErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.NoViableAltException e) voidrecover(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.RecognitionException e) org.antlr.v4.runtime.TokenrecoverInline(org.antlr.v4.runtime.Parser recognizer) protected voidreportFailedPredicate(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.FailedPredicateException e) protected voidreportInputMismatch(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.InputMismatchException e) protected voidreportNoViableAlternative(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.NoViableAltException e) voidsync(org.antlr.v4.runtime.Parser recognizer) Methods inherited from class org.antlr.v4.runtime.DefaultErrorStrategy
beginErrorCondition, constructToken, consumeUntil, endErrorCondition, escapeWSAndQuote, getErrorRecoverySet, getExpectedTokens, getMissingSymbol, getSymbolText, getSymbolType, getTokenErrorDisplay, inErrorRecoveryMode, notifyErrorListeners, reportError, reportMatch, reportMissingToken, reportUnwantedToken, reset, singleTokenDeletion, singleTokenInsertion
-
Constructor Details
-
DescriptiveErrorStrategy
public DescriptiveErrorStrategy(org.antlr.v4.runtime.CharStream charStream) Fail-fast strategy with friendly diagnostics.- Parameters:
charStream- source character stream used for snippet extraction
-
-
Method Details
-
create
public static org.antlr.v4.runtime.ANTLRErrorStrategy create(org.antlr.v4.runtime.CharStream charStream, boolean recover) Select fail-fast or recovering strategy.- Parameters:
charStream- source character stream used for snippet extractionrecover-truefor multi-error resync;falsefor fail-fast- Returns:
- an error strategy instance (never
null)
-
recover
public void recover(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.RecognitionException e) Mark incomplete contexts, emit a friendly LL diagnostic, then cancel.
- Specified by:
recoverin interfaceorg.antlr.v4.runtime.ANTLRErrorStrategy- Overrides:
recoverin classorg.antlr.v4.runtime.DefaultErrorStrategy
-
recoverInline
public org.antlr.v4.runtime.Token recoverInline(org.antlr.v4.runtime.Parser recognizer) throws org.antlr.v4.runtime.RecognitionException Bail-style: never return a synthetic token; report then cancel.
- Specified by:
recoverInlinein interfaceorg.antlr.v4.runtime.ANTLRErrorStrategy- Overrides:
recoverInlinein classorg.antlr.v4.runtime.DefaultErrorStrategy- Throws:
org.antlr.v4.runtime.RecognitionException
-
sync
public void sync(org.antlr.v4.runtime.Parser recognizer) No-op (matches
BailErrorStrategy) so SLL stays cheap.- Specified by:
syncin interfaceorg.antlr.v4.runtime.ANTLRErrorStrategy- Overrides:
syncin classorg.antlr.v4.runtime.DefaultErrorStrategy
-
createNoViableAlternativeErrorMessage
protected String createNoViableAlternativeErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.NoViableAltException e) -
reportNoViableAlternative
protected void reportNoViableAlternative(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.NoViableAltException e) - Overrides:
reportNoViableAlternativein classorg.antlr.v4.runtime.DefaultErrorStrategy
-
createInputMismatchErrorMessage
protected String createInputMismatchErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.InputMismatchException e) -
reportInputMismatch
protected void reportInputMismatch(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.InputMismatchException e) - Overrides:
reportInputMismatchin classorg.antlr.v4.runtime.DefaultErrorStrategy
-
createFailedPredicateErrorMessage
protected String createFailedPredicateErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.FailedPredicateException e) Format a failed-predicate diagnostic.recognizeris part of the protected hook surface (parity withcreateNoViableAlternativeErrorMessage(org.antlr.v4.runtime.Parser, org.antlr.v4.runtime.NoViableAltException)/createInputMismatchErrorMessage(org.antlr.v4.runtime.Parser, org.antlr.v4.runtime.InputMismatchException)) so subclasses can include parser state when customising the message. -
reportFailedPredicate
protected void reportFailedPredicate(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.FailedPredicateException e) - Overrides:
reportFailedPredicatein classorg.antlr.v4.runtime.DefaultErrorStrategy
-