Class LookaheadIterator

Constructors

  • Create a new lookahead iterator for this language and parse state.

    This returns null if the state is invalid for this language.

    Iterating LookaheadIterator will yield valid symbols in the given parse state. Newly created lookahead iterators will have currentType populated with the ERROR symbol.

    Lookahead iterators can be useful to generate suggestions and improve syntax error diagnostics. To get symbols valid in an ERROR node, use the lookahead iterator on its first leaf node state. For MISSING nodes, a lookahead iterator created on the previous non-extra leaf node may be appropriate.

    Parameters

    • language: Language

      The language to use for the lookahead iterator

    • state: number

      The parse state to use for the lookahead iterator

    Returns LookaheadIterator

Properties

currentType: string

The current symbol name of the lookahead iterator.

currentTypeId: number

The current symbol of the lookahead iterator.

Methods

  • Get an iterator for the lookahead iterator.

    This allows the lookahead iterator to be used in a for-of loop, iterating over the valid symbols in the current parse state.

    Returns Iterator<string>

    An iterator over the symbol names

  • Reset the lookahead iterator.

    This returns true if the language was set successfully and false otherwise.

    Parameters

    • language: Language

      The language to use for the lookahead iterator

    • stateId: number

      The parse state to use for the lookahead iterator

    Returns boolean

  • Reset the lookahead iterator to another state.

    This returns true if the iterator was reset to the given state and false otherwise.

    Parameters

    • stateId: number

      The parse state to reset the lookahead iterator to

    Returns boolean