LookaheadIterator#
- class tree_sitter.LookaheadIterator#
Bases:
IteratorA 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
ERRORnode, use the lookahead iterator on its first leaf node state. ForMISSINGnodes, 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_namesmethod
- reset(state, language=None)#
Reset the lookahead iterator.
- Returns:
Trueif it was reset successfully orFalseif it failed.
Added in version 0.25.0: Replaces the
reset_statemethod
- 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
ERRORsymbol.
- current_symbol_name#
The current symbol name.
- language#
The current language.