Class Language
java.lang.Object
io.github.treesitter.jtreesitter.Language
- All Implemented Interfaces:
Cloneable
A class that defines how to parse a particular language.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe latest ABI version that is supported by the current version of the library.static final intThe earliest ABI version that is supported by the current version of the library. -
Constructor Summary
ConstructorsConstructorDescriptionLanguage(MemorySegment self) Creates a new instance from the given language pointer. -
Method Summary
Modifier and TypeMethodDescriptionclone()Get another reference to the language.booleanintGet the ABI version number for this language.intGet the number of distinct field names in this languageshortgetFieldIdForName(String name) Get the numerical ID for the given field name.getFieldNameForId(short id) Get the field name for the given numerical id.Get the metadata for this language, if available.getName()Get the name of this language, if available.intGet the number of valid states in this languageshort[]getSubtypes(short supertype) Get all symbols for a given supertype symbol.short[]Get all supertype symbols for the language.intGet the number of distinct node types in this language.shortgetSymbolForName(String name, boolean isNamed) Get the numerical ID for the given node type, or0if not found.getSymbolName(short symbol) Get the node type for the given numerical ID.intDeprecated, for removal: This API element is subject to removal in a future version.inthashCode()booleanisNamed(short symbol) Check if the node for the given numerical ID is named.booleanisSupertype(short symbol) Check if the node for the given numerical ID is a supertype.booleanisVisible(short symbol) Check if the node for the given numerical ID is visible.static Languageload(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.shortnextState(short state, short symbol) Get the next parse state.Deprecated.Use theQueryconstructor instead.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:
UnsatisfiedLinkError- If the language symbol could not be found.RuntimeException- If the language could not be loaded.- Since:
- 0.23.1
-
getAbiVersion
Get the ABI version number for this language.This version number is used to ensure that languages were generated by a compatible version of Tree-sitter.
- Since:
- 0.25.0
-
getVersion
Deprecated, for removal: This API element is subject to removal in a future version.UsegetAbiVersion()instead.Get the ABI version number for this language. -
getName
-
getMetadata
Get the metadata for this language, if available.- Since:
- 0.25.0
- API Note:
- This information is generated by the Tree-sitter
CLI and relies on the language author providing the correct
metadata in the language's
tree-sitter.jsonfile.
-
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 -
getSupertypes
-
getSubtypes
-
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
Deprecated.Use theQueryconstructor instead.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
-
getAbiVersion()instead.