Language#
- class tree_sitter.Language(ptr)#
A class that defines how to parse a particular language.
Methods#
- copy()#
Create a copy of the language.
- field_id_for_name(name, /)#
Get the numerical id for the given field name.
- field_name_for_id(field_id, /)#
Get the field name for the given numerical id.
- id_for_node_kind(kind, named, /)#
Get the numerical id for the given node kind.
- lookahead_iterator(state, /)#
Create a new
LookaheadIterator
for this language and parse state.
- next_state(state, id, /)#
Get the next parse state.
Tip
Combine this with
lookahead_iterator
to generate completion suggestions or valid symbols in error nodes.Examples
>>> state = language.next_state(node.parse_state, node.grammar_id)
- node_kind_for_id(id, /)#
Get the name of the node kind for the given numerical id.
- node_kind_is_named(id, /)#
Check if the node type for the given numerical id is named (as opposed to an anonymous node type).
- node_kind_is_supertype(id, /)#
Check if the node type for the given numerical id is a supertype.
Supertype nodes represent abstract categories of syntax nodes (e.g. “expression”).
- node_kind_is_visible(id, /)#
Check if the node type for the given numerical id is visible (as opposed to an auxiliary node type).
- query(source, /)#
Create a new
Query
from a string containing one or more S-expression patterns.Deprecated since version 0.25.0: Use the
Query
constructor instead.
- subtypes(supertype, /)#
Get all subtype symbol IDs for a given supertype symbol.
Added in version 0.25.0.
Special Methods#
- __copy__()#
Use
copy.copy()
to create a copy of the language.
- __eq__(value, /)#
Implements
self==value
.
- __hash__()#
Implements
hash(self)
.Important
On 32-bit platforms, you must use
hash(self) & 0xFFFFFFFF
to get the actual hash.
- __ne__(value, /)#
Implements
self!=value
.
- __repr__()#
Implements
repr(self)
.
Attributes#
- abi_version#
The ABI version number that indicates which version of the Tree-sitter CLI was used to generate this language.
Added in version 0.25.0.
- field_count#
The number of distinct field names in this language.
- name#
The name of the language.
Added in version 0.25.0.
- node_kind_count#
The number of distinct node types in this language.
- parse_state_count#
The number of valid states in this language.
- semantic_version#
The Semantic Version of the language.
Added in version 0.25.0.
- supertypes#
The supertype symbols of the language.
Added in version 0.25.0.
- version#
The ABI version number that indicates which version of the Tree-sitter CLI was used to generate this language.
Deprecated since version 0.25.0: Use
abi_version
instead.