Language struct defines how to parse a particular programming language. Language instances are typically generated by the Tree-sitter CLI and exported by language-specific crates.
Creating a Language
new
LanguageFn
required
A function that returns a pointer to the language’s internal structure
Language Information
name
None for older parsers that don’t include name metadata.
abi_version
metadata
tree-sitter.json file.
Returns: Some(LanguageMetadata) if metadata is available, or None for older parsers.
Node Types
node_kind_count
node_kind_for_id
u16
required
The numerical id of the node kind
Some(&str) with the node kind name, or None if the id is invalid.
id_for_node_kind
&str
required
The name of the node kind
bool
required
Whether to look for a named or anonymous node kind
node_kind_is_named
u16
required
The numerical id of the node kind
node_kind_is_visible
node_kind_is_supertype
Fields
field_count
field_name_for_id
u16
required
The numerical id of the field
Some(&str) with the field name, or None if the id is invalid.
field_id_for_name
impl AsRef<[u8]>
required
The name of the field
Some(FieldId) if the field exists, or None if it doesn’t.
Supertypes
supertypes
subtypes_for_supertype
u16
required
The id of the supertype
Parse States
parse_state_count
next_state
lookahead_iterator to generate completion suggestions or valid symbols in error nodes.
u16
required
The current parse state
u16
required
The grammar symbol id
Lookahead
lookahead_iterator
None if state is invalid for this language.
u16
required
The parse state to create the iterator for
Some(LookaheadIterator) if the state is valid, or None otherwise.
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.
LookaheadIterator
An iterator over valid symbols in a parse state.current_symbol
current_symbol_name
language
reset
&Language
required
The language to use
u16
required
The parse state
true if the reset was successful, false otherwise.
reset_state
u16
required
The parse state
true if the reset was successful, false otherwise.
iter_names
LookaheadIterator also implements the standard Iterator trait, yielding symbol ids:
LanguageMetadata
Metadata associated with a language, including semantic version information.u8
The major version number
u8
The minor version number
u8
The patch version number