Language#

class tree_sitter.Language(ptr)#

A class that defines how to parse a particular language.

Changed in version 0.22.0: No longer accepts a name parameter.

Methods#

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

__eq__(value, /)#

Implements self==value.

Added in version 0.22.0.

__hash__()#

Implements hash(self).

Important

On 32-bit platforms, you must use hash(self) & 0xFFFFFFFF to get the actual hash.

Added in version 0.22.0.

__ne__(value, /)#

Implements self!=value.

Added in version 0.22.0.

__repr__()#

Implements repr(self).

Added in version 0.22.0.

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.