The Language API provides functions for accessing information about Tree-sitter language definitions, including symbols, fields, and metadata.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tree-sitter/tree-sitter/llms.txt
Use this file to discover all available pages before exploring further.
Reference counting
ts_language_copy
Get another reference to the given language.The language to reference
ts_language_delete
Free any dynamically-allocated resources for this language, if this is the last reference.The language to dereference
Language properties
ts_language_name
Get the name of this language.The language instance
NULL in older parsers.
Example:
ts_language_abi_version
Get the ABI version number for this language.The language instance
TREE_SITTER_LANGUAGE_VERSION and TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION.
See also ts_parser_set_language.
ts_language_metadata
Get the metadata for this language.The language instance
tree-sitter.json file. The TSLanguageMetadata struct contains:
major_version- Major version numberminor_version- Minor version numberpatch_version- Patch version number
ts_language_is_wasm
Check if the language came from a Wasm module.The language instance
true if the language is from Wasm.
If so, then in order to use this language with a parser, that parser must have a Wasm store assigned.
Symbols
ts_language_symbol_count
Get the number of distinct node types in the language.The language instance
ts_language_state_count
Get the number of valid states in this language.The language instance
ts_language_symbol_name
Get a node type string for the given numerical id.The language instance
The symbol ID
ts_language_symbol_for_name
Get the numerical id for the given node type string.The language instance
The symbol name
Length of the string
Whether to look for a named symbol
ts_language_symbol_type
Check whether the given node type id belongs to named nodes, anonymous nodes, or hidden nodes.The language instance
The symbol ID
TSSymbolTypeRegular, TSSymbolTypeAnonymous, TSSymbolTypeSupertype, or TSSymbolTypeAuxiliary.
See also ts_node_is_named. Hidden nodes are never returned from the API.
Fields
ts_language_field_count
Get the number of distinct field names in the language.The language instance
ts_language_field_name_for_id
Get the field name string for the given numerical id.The language instance
The field ID
ts_language_field_id_for_name
Get the numerical id for the given field name string.The language instance
The field name
Length of the name
Supertypes and subtypes
ts_language_supertypes
Get a list of all supertype symbols for the language.The language instance
Output parameter for the array length
ts_language_subtypes
Get a list of all subtype symbol ids for a given supertype symbol.The language instance
The supertype symbol
Output parameter for the array length
ts_language_supertypes for fetching all supertype symbols.
Parse states
ts_language_next_state
Get the next parse state.The language instance
The current parse state
The grammar symbol to transition on
ts_node_grammar_symbol for valid symbols.
Lookahead iterators
ts_lookahead_iterator_new
Create a new lookahead iterator for the given language and parse state.The language instance
The parse state
NULL if the state is invalid.
Repeatedly using ts_lookahead_iterator_next and ts_lookahead_iterator_current_symbol will generate valid symbols in the given parse state. Newly created lookahead iterators will contain the ERROR symbol.
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.
Example:
ts_lookahead_iterator_delete
Delete a lookahead iterator, freeing all the memory used.The iterator to delete
ts_lookahead_iterator_reset_state
Reset the lookahead iterator to another state.The iterator instance
The new parse state
true if the iterator was reset, false if the state is invalid.
ts_lookahead_iterator_reset
Reset the lookahead iterator to a different language and state.The iterator instance
The new language
The new parse state
true if the language was set successfully, false otherwise.
ts_lookahead_iterator_language
Get the current language of the lookahead iterator.The iterator instance
ts_lookahead_iterator_next
Advance the lookahead iterator to the next symbol.The iterator instance
true if there is a new symbol, false otherwise.
ts_lookahead_iterator_current_symbol
Get the current symbol of the lookahead iterator.The iterator instance
ts_lookahead_iterator_current_symbol_name
Get the current symbol type of the lookahead iterator as a null-terminated string.The iterator instance