ts::Language class

Tree-Sitter language grammar.

This can be inspected (e.g. the nodes it can produce) and used for parsing.

Use this when creating the parser.

Constructors, destructors, conversion operators

Language(const TSLanguage*) noexcept
Constructor to create a Language from a raw TSLanguage pointer.

Public functions

auto raw() const -> const TSLanguage*
Get the raw TSLanguage pointer.
auto node_type_count() const -> std::uint32_t
The number of distinct node types in the language.
auto node_type_name(TypeId) const -> const char*
The node type string for the given numberic TypeId.
auto node_type_id(std::string_view, bool is_named) const -> TypeId
The numeric TypeId for the given node type string.
auto field_count() const -> std::uint32_t
The number of distrinct field names in the langauge.
auto field_name(FieldId) const -> const char*
The field name string for the given numeric FieldId.
auto field_id(std::string_view) const -> FieldId
The numeric FieldId for the given field name string.
auto node_type_kind(TypeId) const -> TypeKind
The kind of a node TypeId.
auto version() const -> std::uint32_t
The Tree-Sitter ABI version for this language.

Function documentation

const TSLanguage* ts::Language::raw() const

Get the raw TSLanguage pointer.

TypeId ts::Language::node_type_id(std::string_view, bool is_named) const

The numeric TypeId for the given node type string.

FieldId ts::Language::field_id(std::string_view) const

The numeric FieldId for the given field name string.

std::uint32_t ts::Language::version() const

The Tree-Sitter ABI version for this language.

Used to check if language was generated by a compatible version of Tree-Sitter.

See: TREE_SITTER_VERSION, TREE_SITTER_MIN_VERSION