LookaheadIterator#

class tree_sitter.LookaheadIterator#

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#

iter_names()#

Iterate symbol names.

reset(language, state, /)#

Reset the lookahead iterator.

Deprecated since version 0.22.0: Use reset_state() instead.

Returns:

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

reset_state(state, language=None)#

Reset the lookahead iterator.

Returns:

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

Special methods#

__iter__()#

Implements iter(self).

__next__()#

Implements next(self).

Attributes#

current_symbol#

The current symbol.

Newly created iterators will return the ERROR symbol.

current_symbol_name#

The current symbol name.

language#

The current language.