Skip to content

Upstream Conformance โ€‹

Relationship โ€‹

text
Upstream Tree-sitter (C)
        โ†“ studied as a behavioral and algorithmic reference
        โ†“ (no code vendored, no symbols linked, no headers imported)
tree-sitter.zig (native Zig)

Concepts carried over: table-driven LR parsing with shift/reduce/accept, error-cost recovery with ERROR/MISSING nodes, reusable-subtree incremental parsing, changed ranges, byte-plus-point coordinates, and structural S-expression queries with captures and predicates.

What conformance means here โ€‹

  • Differential corpus (src/debug/corpus/, zig build conformance): reference S-expressions for all bundled grammars plus incremental-vs-fresh equality checks. Embedded once and also executed by zig build test, so the report and the suite cannot drift.
  • Behavioral tests assert tree shapes, node properties, ranges, recovery outcomes, reuse counts, and query matches against hand-verified expectations.
  • Deliberate differences from upstream C: the query engine covers the documented predicate/quantifier/directive subset (no WASM store needed โ€” see below), error costs use a smaller equivalent scale, and scanner snapshots use reset-plus-monotonic-offsets instead of serialize/deserialize. Each is marked in the Feature Matrix.

C library coverage (tree-sitter/lib/src) โ€‹

Every upstream runtime file was studied as a behavioral reference and has a native counterpart below; nothing was wrapped, linked, or vendored (the reference clone has since been removed from this repository):

Upstream file(s)Native counterpartNotes
alloc.c/hsrc/memory/ (allocator, arena, ownership, refcount)Explicit allocators, no globals
array.hsrc/utils/array.zig (+ std ArrayList)
atomic.hstd.atomic via memory/refcount.zig
error_costs.hsrc/parser/recover.zigEquivalent relative costs, smaller scale (1/skip, 2/missing + op budgets)
get_changed_ranges.c/hsrc/tree/changed_ranges.zigStructural minimal diffs
host.h, portable/endian.hZig builtin + explicit LE/BE in unicode/utf16.zigNo platform branches in user code
language.c/hsrc/language/ (model, symbols, tables, fields, aliases, metadata)Plus 4 bundled table sets
length.hsrc/core/position.zig (Length)
lexer.c/hsrc/lexer/ + src/parser/lookahead.zigExternal-first dispatch, per-offset scan cache
lib.csrc/treesitter.zig facade
node.csrc/tree/node.zigHandle-based, allocation-free reads
parser.c/hsrc/parser/ (engine, stack, actions, reduce, recovery, state)Reuse via sorted interval index
point.c/hsrc/core/point.zig
query.csrc/query/ (compiler, matcher, predicates, directives, cursors)NFA-alternative backtracking matcher, same anchor/predicate semantics
reduce_action.hsrc/parser/actions.zig, reduce.zigAlias substitution applied here
reusable_node.hParser.candidates + cloneSubtreeContiguous child cloning, scratch discipline
stack.c/hsrc/parser/stack.zig
subtree.c/hsrc/tree/subtree.zigPooled nodes + child indices
tree.c/hsrc/tree/tree.zig (+ edit.zig, sexp.zig)Ownership-explicit trees
tree_cursor.c/hsrc/tree/cursor.zigField tracking included
ts_assert.hsrc/utils/assertions.zig
unicode/* (ICU tables, utf8/utf16 headers)src/unicode/ (tables, utf8, utf16)Strict decoding; UTF-16 transcode
wasm_store.c/h, wasm-stdlib/*Intentionally absentGrammars are native Zig data and scanners are Zig code, so no WASM loader or C shims are needed โ€” including on wasm32-wasi itself

Development: Conformance, Error Recovery

Released under the MIT License.