Class LookaheadIterator
java.lang.Object
io.github.treesitter.jtreesitter.LookaheadIterator
- All Implemented Interfaces:
AutoCloseable, Iterator<LookaheadIterator.Symbol>
@NullMarked
public final class LookaheadIterator
extends Object
implements AutoCloseable, Iterator<LookaheadIterator.Symbol>
A class that is used to look up valid symbols in a specific parse state.
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA class that pairs a symbol ID with its name. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()shortGet the current symbol ID.The current symbol name.Get the current language of the lookahead iterator.booleanhasNext()Check if the lookahead iterator has more symbols.names()Iterate over the symbol names.next()Advance the lookahead iterator to the next symbol.booleanreset(short state) Reset the lookahead iterator to the given state.booleanReset the lookahead iterator to the given state and another language.symbols()Iterate over the symbol IDs.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterator
forEachRemaining
-
Method Details
-
getLanguage
Get the current language of the lookahead iterator. -
getCurrentSymbol
Get the current symbol ID.- API Note:
- The ID of the ERROR symbol is equal to
-1.
-
getCurrentSymbolName
The current symbol name.- API Note:
- Newly created lookahead iterators will contain the ERROR symbol.
-
reset
Reset the lookahead iterator to the given state.- Returns:
trueif the iterator was reset successfully orfalseif it failed.
-
reset
-
hasNext
public boolean hasNext()Check if the lookahead iterator has more symbols.- Specified by:
hasNextin interfaceIterator<LookaheadIterator.Symbol>
-
next
Advance the lookahead iterator to the next symbol.- Specified by:
nextin interfaceIterator<LookaheadIterator.Symbol>- Throws:
NoSuchElementException- If there are no more symbols.
-
symbols
-
names
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
RuntimeException
-