# Parsing

ahto parses the source files of the lake into tables of declarations, imports, calls, comments and syntax trees, once per distinct blob. A crawl does it after it
publishes, so the code browser, the workbench and SQL can ask what a function calls, who
imports a package or where a name is used.

## Languages

ahto parses Go with Go's own `go/parser` and every other language with a tree-sitter grammar.
The [languages table](/docs/languages) lists them with their extensions.

The grammars are vendored under `third_party/treesitter` and compiled into `ahto`
with cgo. A build without cgo parses Go only. The Noir grammar is GPL-3.0, so the binaries
ahto ships leave it out; build with `-tags noir` to parse `.nr` files.

## The tables

| Table | One row per |
|---|---|
| `parse_status` | source blob: parsed, parsed with syntax errors, or skipped (too large or generated), with its language and parser |
| `symbols` | declaration: function, method, type, struct, interface, variable, constant or field, with its signature, body hash and doc |
| `imports` | import of a file, with its alias |
| `symbol_refs` | identifier that uses a name, resolved to its declaration in the same file when it can be |
| `calls` | call, with its callee, how it resolved and the declaration it is inside |
| `comments` | comment, with the declaration it documents and whether it is a directive |
| `syntax_nodes` | node of the raw syntax tree; the `syntax_tree` view gives each node its index, parent and offsets |

`ahto query schema <table>` gives every column with what it means. The full design, and what
is still to come (cross-file symbol resolution), is in
the source intelligence design document.

## When files are parsed

A crawl parses the new source blobs after it derives the read models, and
`ahto parse [--repo]` does the same on its own. `crawl --no-parse` leaves the parse stage
out for one crawl, and `lake.parse.enabled: false` for every crawl; `ahto parse` catches up
later.

A blob is parsed once, and parsed again only in two cases:

- **Automatically, when ahto's extraction changes.** Each `parse_status` row records the
  extraction version that wrote it (the last word of `parser`, such as `v1`). When a newer
  ahto extracts more or differently, the next crawl or `ahto parse` parses every blob an
  older version parsed and drops its old rows, in the same publish. Nothing has to be
  dropped by hand.
- **On purpose, with `ahto parse --rebuild`.** It parses every source blob again, whatever
  version parsed it, and replaces its rows. Use it after a crash or an interrupted run you
  do not trust, on a lake whose parsing tables look wrong, after changing
  `lake.parse.max_bytes` or `skip_generated`, or to write the tables anew. It takes
  `--repo` (only the blobs of those repositories), `--no-syntax-nodes` and
  `--lock-timeout` like the rest of `ahto parse`.

Either way the new rows and the dropped ones are published together, so a blob never
counts twice. `ahto parse` reports how many blobs it parsed again as `reparsed`.

## Syntax trees

`ahto inspect --ast <ref>:<path>` prints the syntax tree of one file, and the `GetSyntax`
rpc of the [source service](/docs/gateway#the-source-service) returns it, for any language
ahto parses.

`syntax_nodes` is by far the largest parsing table, and it is on by default
(`lake.parse.syntax_nodes`). For the whole history of golang/go (191,272 distinct Go blobs,
6.90 GB of source) it is 1.04 billion rows and 3.1 GB on disk, out of 4.84 GB for all the
parsing tables, and it adds 18 to 28 s to a parse that takes 30 s without it (Apple M4 Pro,
14 cores, measured 2026-11-23). `--no-syntax-nodes` on `crawl` or `parse` leaves it out for
one run; `inspect --ast` and `GetSyntax` then parse the file again when asked.
`ahto storage status` shows its size.