Reference counting
ts_language_copy
Get another reference to the given language.const TSLanguage *
The language to reference
ts_language_delete
Free any dynamically-allocated resources for this language, if this is the last reference.const TSLanguage *
The language to dereference
Language properties
ts_language_name
Get the name of this language.const TSLanguage *
The language instance
NULL in older parsers.
Example:
ts_language_abi_version
Get the ABI version number for this language.const TSLanguage *
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.const TSLanguage *
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.const TSLanguage *
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.const TSLanguage *
The language instance
ts_language_state_count
Get the number of valid states in this language.const TSLanguage *
The language instance
ts_language_symbol_name
Get a node type string for the given numerical id.const TSLanguage *
The language instance
TSSymbol
The symbol ID
ts_language_symbol_for_name
Get the numerical id for the given node type string.const TSLanguage *
The language instance
const char *
The symbol name
uint32_t
Length of the string
bool
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.const TSLanguage *
The language instance
TSSymbol
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.const TSLanguage *
The language instance
ts_language_field_name_for_id
Get the field name string for the given numerical id.const TSLanguage *
The language instance
TSFieldId
The field ID
ts_language_field_id_for_name
Get the numerical id for the given field name string.const TSLanguage *
The language instance
const char *
The field name
uint32_t
Length of the name
Supertypes and subtypes
ts_language_supertypes
Get a list of all supertype symbols for the language.const TSLanguage *
The language instance
uint32_t *
Output parameter for the array length
ts_language_subtypes
Get a list of all subtype symbol ids for a given supertype symbol.const TSLanguage *
The language instance
TSSymbol
The supertype symbol
uint32_t *
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.const TSLanguage *
The language instance
TSStateId
The current parse state
TSSymbol
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.const TSLanguage *
The language instance
TSStateId
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.TSLookaheadIterator *
The iterator to delete
ts_lookahead_iterator_reset_state
Reset the lookahead iterator to another state.TSLookaheadIterator *
The iterator instance
TSStateId
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.TSLookaheadIterator *
The iterator instance
const TSLanguage *
The new language
TSStateId
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.const TSLookaheadIterator *
The iterator instance
ts_lookahead_iterator_next
Advance the lookahead iterator to the next symbol.TSLookaheadIterator *
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.const TSLookaheadIterator *
The iterator instance
ts_lookahead_iterator_current_symbol_name
Get the current symbol type of the lookahead iterator as a null-terminated string.const TSLookaheadIterator *
The iterator instance