Skip to content

Architecture โ€‹

text
                    tree-sitter.zig
                           โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚                  โ”‚                  โ”‚
      Parser             Tree              Query
        โ”‚                  โ”‚                  โ”‚
   โ”Œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”
   โ”‚    โ”‚    โ”‚       โ”‚     โ”‚     โ”‚       โ”‚    โ”‚    โ”‚
 Lexer Stack Actions Node Cursor Edit  Pattern Capture Matcher
   โ”‚
 Input
   โ”‚
 Unicode
   โ”‚
 Language

In plain language โ€‹

Source text flows downward: input bytes are tokenized by the lexer, assembled into a tree by the parser using language tables, and then read through nodes, cursors, or queries. Edits flow back up: an edit plus an old tree reuses subtrees to build a new tree cheaply.

Dependency direction โ€‹

Low-level code never imports high-level code:

text
utils โ†’ core โ†’ memory โ†’ input/unicode โ†’ language โ†’ tree โ†’ lexer โ†’ parser โ†’ query

core (points, ranges, edits, symbols) knows nothing about parsing; utils is pure helpers over the standard library. Each subsystem exposes a facade (parser/parser.zig, tree/tree.zig, โ€ฆ) re-exported by src/treesitter.zig.

Released under the MIT License.