Tree โ
Overview โ
Tree owns a parse result: the source copy, the node pool, and the child-index buffer. Source: src/tree/tree.zig.
Lifecycle โ
var tree = try parser.parseString("1 + 2");
defer tree.deinit();Methods โ
deinit โ
pub fn deinit(self: *Tree) voidFrees source, pool, and indices. Nodes and cursors borrowed from the tree must not outlive it.
rootNode โ
pub fn rootNode(self: *const Tree) NodeHandle to the start-symbol node. Never allocates.
cursor โ
pub fn cursor(self: *const Tree) TreeCursorTraversal cursor inheriting the tree's allocator. Prefer over TreeCursor.init(gpa, node).
languageOf / sourceText / nodeCount / hasError โ
pub fn languageOf(self: *const Tree) Language
pub fn sourceText(self: *const Tree) []const u8
pub fn nodeCount(self: *const Tree) usize
pub fn hasError(self: *const Tree) boolgetNode โ
pub fn getNode(self: *const Tree, index: u32) *const SubtreePool access for advanced tooling.
copy โ
pub fn copy(self: *const Tree) Allocator.Error!TreeDeep duplicate (source, nodes, indices) with the tree's allocator.
includedRange โ
pub fn includedRange(self: *const Tree) RangeSpan of the root node (empty range for an empty tree).
getChangedRanges / freeChangedRanges โ
pub fn getChangedRanges(self: *const Tree, other: *const Tree) Allocator.Error![]Range
pub fn freeChangedRanges(self: *const Tree, ranges: []Range) voidDiff against another tree using the caller's allocator; free with either tree sharing it.
Ownership โ
Owns source + pools; borrows allocator and language tables. Streaming parses (parseStream) transfer the pull buffer as the source with no extra copy.
S-expressions โ
treesitter.sexp_mod.toSexp(gpa, node) renders a canonical single-line S-expression ((type child ...), (type "text") leaves, "text" anonymous tokens, (MISSING type)) for debugging and for the conformance corpus.
