LookaheadIterator#

class tree_sitter.LookaheadIterator#

Bases: Iterator

A class that is used to look up symbols valid in a specific parse state.

Tip

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.

Methods#

names()#

Get a list of all symbol names.

Added in version 0.25.0: Replaces the iter_names method

reset(state, language=None)#

Reset the lookahead iterator.

Returns:

True if it was reset successfully or False if it failed.

Added in version 0.25.0: Replaces the reset_state method

symbols()#

Get a list of all symbol IDs.

Added in version 0.25.0.

Special Methods#

__iter__()#

Implements iter(self).

Changed in version 0.25.0: Iterates over tuple[int, str]

__next__()#

Implements next(self).

Changed in version 0.25.0: Yields tuple[int, str]

Attributes#

current_symbol#

The current symbol ID.

Newly created iterators will return the ERROR symbol.

current_symbol_name#

The current symbol name.

language#

The current language.