Package org.apache.groovy.parser.antlr4.internal

# Class DescriptiveErrorStrategy

java.lang.Object
org.antlr.v4.runtime.DefaultErrorStrategy
org.apache.groovy.parser.antlr4.internal.DescriptiveErrorStrategy

All Implemented Interfaces:
  `org.antlr.v4.runtime.ANTLRErrorStrategy`

public class DescriptiveErrorStrategy extends org.antlr.v4.runtime.DefaultErrorStrategy
Fail-fast parser error strategy with friendly diagnostics (default Parrot mode).

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.

See Also:
  - `RecoveringDescriptiveErrorStrategy`
  - `CompilerConfiguration.ERROR_RECOVERY`

- ## Field Summary

  ### Fields inherited from class org.antlr.v4.runtime.DefaultErrorStrategy

  `errorRecoveryMode, lastErrorIndex, lastErrorStates, nextTokensContext, nextTokensState`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DescriptiveErrorStrategy(org.antlr.v4.runtime.CharStream charStream)`
  Fail-fast strategy with friendly diagnostics.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static org.antlr.v4.runtime.ANTLRErrorStrategy`
  `create(org.antlr.v4.runtime.CharStream charStream, boolean recover)`
  Select fail-fast or recovering strategy.
  `protected String`
  `createFailedPredicateErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.FailedPredicateException e)`
  Format a failed-predicate diagnostic.
  `protected String`
  `createInputMismatchErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.InputMismatchException e)`
  `protected String`
  `createNoViableAlternativeErrorMessage(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.NoViableAltException e)`
  `void`
  `recover(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.RecognitionException e)`
  `org.antlr.v4.runtime.Token`
  `recoverInline(org.antlr.v4.runtime.Parser recognizer)`
  `protected void`
  `reportFailedPredicate(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.FailedPredicateException e)`
  `protected void`
  `reportInputMismatch(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.InputMismatchException e)`
  `protected void`
  `reportNoViableAlternative(org.antlr.v4.runtime.Parser recognizer, org.antlr.v4.runtime.NoViableAltException e)`
  `void`
  `sync(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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.antlr.v4.runtime.ANTLRErrorStrategy

  `isSyncRequired`

- ## 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 extraction
      `recover` - `true` for multi-error resync; `false` for 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:
      `recover` in interface `org.antlr.v4.runtime.ANTLRErrorStrategy`
    Overrides:
      `recover` in class `org.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:
      `recoverInline` in interface `org.antlr.v4.runtime.ANTLRErrorStrategy`
    Overrides:
      `recoverInline` in class `org.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:
      `sync` in interface `org.antlr.v4.runtime.ANTLRErrorStrategy`
    Overrides:
      `sync` in class `org.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:
      `reportNoViableAlternative` in class `org.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:
      `reportInputMismatch` in class `org.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.

    `recognizer` is part of the protected hook surface (parity with `createNoViableAlternativeErrorMessage(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:
      `reportFailedPredicate` in class `org.antlr.v4.runtime.DefaultErrorStrategy`