Package io.github.treesitter.jtreesitter
Class Language
java.lang.Object
io.github.treesitter.jtreesitter.Language
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The latest ABI version that is supported by the current version of the library.static final int
The earliest ABI version that is supported by the current version of the library. -
Constructor Summary
ConstructorDescriptionLanguage
(MemorySegment self) Creates a new instance from the given language pointer. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Get another reference to the language.boolean
int
Get the number of distinct field names in this languageshort
getFieldIdForName
(String name) Get the numerical ID for the given field name.getFieldNameForId
(short id) Get the field name for the given numerical id.int
Get the number of valid states in this languageint
Get the number of distinct node types in this language.short
getSymbolForName
(String name, boolean isNamed) Get the numerical ID for the given node type, or0
if not found.getSymbolName
(short symbol) Get the node type for the given numerical ID.int
Get the ABI version number for this language.int
hashCode()
boolean
isNamed
(short symbol) Check if the node for the given numerical ID is named.boolean
isSupertype
(short symbol) Check if the node for the given numerical ID is a supertype.boolean
isVisible
(short symbol) Check if the node for the given numerical ID is visible.static Language
load
(SymbolLookup symbols, String language) Load a language by looking for its function in the given symbols.lookaheadIterator
(short state) Create a new lookahead iterator for the given parse state.short
nextState
(short state, short symbol) Get the next parse state.Create a new query from a string containing one or more S-expression patterns.toString()
-
Field Details
-
LANGUAGE_VERSION
The latest ABI version that is supported by the current version of the library.- API Note:
- The Tree-sitter library is generally backwards-compatible with languages generated using older CLI versions, but is not forwards-compatible.
-
MIN_COMPATIBLE_LANGUAGE_VERSION
The earliest ABI version that is supported by the current version of the library.
-
-
Constructor Details
-
Language
Creates a new instance from the given language pointer.- Throws:
IllegalArgumentException
- If the language version is incompatible.- Implementation Note:
- It is up to the caller to ensure that the pointer is valid.
-
-
Method Details
-
load
Load a language by looking for its function in the given symbols.Example
String library = System.mapLibraryName("tree-sitter-java"); SymbolLookup symbols = SymbolLookup.libraryLookup(library, Arena.global()); Language language = Language.load(symbols, "tree_sitter_java");
The Arena used to load the language must not be closed while the language is being used.
- Throws:
RuntimeException
- If the language could not be loaded.- Since:
- 0.23.1
-
getVersion
Get the ABI version number for this language.When a language is generated by the Tree-sitter CLI, it is assigned an ABI version number that corresponds to the current CLI version.
-
getSymbolCount
Get the number of distinct node types in this language. -
getStateCount
Get the number of valid states in this language -
getFieldCount
Get the number of distinct field names in this language -
getSymbolName
-
getSymbolForName
-
isNamed
Check if the node for the given numerical ID is named.- See Also:
-
isVisible
Check if the node for the given numerical ID is visible. -
isSupertype
Check if the node for the given numerical ID is a supertype.- Since:
- 0.24.0
-
getFieldNameForId
-
getFieldIdForName
-
nextState
Get the next parse state.short state = language.nextState(node.getParseState(), node.getGrammarSymbol());
Combine this with
lookaheadIterator(state)
to generate completion suggestions or valid symbols in ERROR nodes. -
lookaheadIterator
Create a new lookahead iterator for the given parse state.- Throws:
IllegalArgumentException
- If the state is invalid for this language.
-
query
Create a new query from a string containing one or more S-expression patterns.- Throws:
QueryError
- If an error occurred while creating the query.
-
clone
-
equals
-
hashCode
-
toString
-