ts namespace

C++ wrapper for the C Tree-Sitter API.

Wrapper types and helper functions for Tree-Sitter.

Classes

struct AppliedEdit
Holds information about an applied Edit.
struct Capture
A capture of a node in a syntax tree.
class Cursor
Allows efficient walking of a Tree.
struct Edit
Used to modify the source code and parse tree.
class EditException
Base class for exceptions related to applying edits to the tree.
struct EditResult
Holds information about all applied edits.
class Language
Tree-Sitter language grammar.
struct Location
Location in source code as row, column and byte offset.
struct Match
A match of a pattern in a syntax tree.
class MultilineEditException
Newlines are not allowed in Edits.
class Node
A syntax node in a parsed tree.
class NullNodeException
Thrown by the constructor of Node if you try to create a null node.
class OverlappingEditException
Overlapping Edits are not allowed.
class ParseFailureException
Thrown by Parser::parse_string (should never actually be thrown).
class Parser
Parser for a Tree-Sitter language.
class ParserLanguageException
Version missmatch between Tree-Sitter and the Language grammar.
struct Point
Location in source code as row and column.
class Query
A query is a "pre-compiled" string of S-expression patterns.
class QueryCursor
Stores the state needed to execute a query and iteratively search for matches.
class QueryException
Syntax error in a Query string.
struct Range
Range in the source code (start and end Points).
class Tree
A syntax tree.
class TreeSitterException
Base exception class for errors in the Tree-Sitter wrapper.
class ZeroSizedEditException
Empty Edits are not allwed.

Enums

enum class TypeKind { Named, Anonymous, Hidden }
Kind of a TypeId.

Typedefs

using TypeId = TSSymbol
Numeric representation of the type of a node.
using FieldId = TSFieldId
Numeric representation of a field.

Functions

auto language_compatible(const Language&) -> bool
Check if a language is compatible with the linked Tree-Sitter version.
void visit_children(Cursor& cursor, const std::function<void(ts::Node)>& fn)
template<typename Fn>
static void visit_tree(const ts::Tree& tree, Fn fn)
auto debug_print_tree(Node node) -> std::string
Prints a debug representation of the tree starting at the node.
auto debug_print_node(Node node) -> std::string
Prints a debug representation of the node (does not print children).
void swap(Cursor& self, Cursor& other) noexcept

Variables

const std::size_t TREE_SITTER_VERSION
Tree-Sitter current language version.
const std::size_t TREE_SITTER_MIN_VERSION
Tree-Sitter minimum supported language version.

Enum documentation

enum class ts::TypeKind

Kind of a TypeId.

Analogous to Tree-Sitters TSSymbolType.

Enumerators
Named

Named.

Anonymous

Anonymous.

Hidden

Hidden (should not be returned by the Api).

Function documentation

void ts::visit_children(Cursor& cursor, const std::function<void(ts::Node)>& fn)

Visits all children of the cursor and call the given function.

template<typename Fn>
static void ts::visit_tree(const ts::Tree& tree, Fn fn)

Visits a tree using a cursor.

std::string ts::debug_print_tree(Node node)

Prints a debug representation of the tree starting at the node.

See debug_print_node.

std::string ts::debug_print_node(Node node)

Prints a debug representation of the node (does not print children).

This is easier to read than Node::as_s_expr and contains more information.

Additional node properties are indicated by a symbol after the node name:

  • has_changes: *
  • has_errors: E
  • is_names: N
  • is_missing: ?
  • is_extra: +

void ts::swap(Cursor& self, Cursor& other) noexcept

Swap function.

Variable documentation

const std::size_t ts::TREE_SITTER_VERSION

Tree-Sitter current language version.

Version for langauges created using the current tree-sitter version.

Can be thought of as the max version for langauges.

const std::size_t ts::TREE_SITTER_MIN_VERSION

Tree-Sitter minimum supported language version.

Minimum supported version of languages.