Language#

class tree_sitter.Language(ptr)#

A class that defines how to parse a particular language.

Methods#

copy()#

Create a copy of the language.

Added in version 0.24.0.

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”).

Added in version 0.24.0.

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.

Special Methods#

__copy__()#

Use copy.copy() to create a copy of the language.

Added in version 0.24.0.

__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#

field_count#

The number of distinct field names in this language.

node_kind_count#

The number of distinct node types in this language.

parse_state_count#

The number of valid states in this language.

version#

The ABI version number that indicates which version of the Tree-sitter CLI was used to generate this Language.