Skip to content

Commit 54cabdb

Browse files
committed
Check the transcriptions against the vendored upstream sources
The keyword table, the %fallback set and "every parse function names its rule" were all things only a careful reading could confirm, and the sort of thing that quietly rots when the pin advances. Three tests now check them mechanically: - token rebuilds the keyword table from mkkeywordhash.c (now vendored alongside parse.y and tokenize.c) and compares all 147 entries and their TK_ codes; - token rebuilds the %fallback set from parse.y and compares all 73, both resolved for the pinned build's feature flags; - parser checks that every one of parse.y's 133 nonterminals is named somewhere in the parser, which is the repository rule read from the side that catches an omission. All three passed on the first run, which is the answer I wanted but not the one worth relying on next time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JzBeCg7rjweVW3uGPg5G7T
1 parent b2ff013 commit 54cabdb

6 files changed

Lines changed: 940 additions & 7 deletions

File tree

CLAUDE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ https://sqlite.org/lang.html.
99
## Rules
1010

1111
- **Zero dependencies.** `go.mod` must never gain a `require` line.
12+
- The keyword table and the `%fallback` set are transcriptions, and tests in
13+
`token` rebuild both from the vendored upstream sources to keep them
14+
honest. Advancing the pin surfaces a keyword change as a failure.
1215
- **No parser generators.** Everything is hand-written recursive descent.
1316
- **Never edit `parser/testdata/*.test` by hand.** Corpus files are produced
1417
by `cmd/regenerate-parse` from SQLite's own test suite plus a real SQLite
1518
build (the oracle). `*.metadata.json` sidecars are updated by tooling
1619
(`go test ./parser -check-parse`), not by hand. The hand-written snapshot
1720
inputs under `parser/testdata/ast/` are the exception — see below.
1821
- Every nontrivial parse function carries a comment naming the `parse.y`
19-
rule(s) it implements.
22+
rule(s) it implements. `TestEveryRuleIsNamed` enforces this from the other
23+
side: no nonterminal of the vendored grammar may go unmentioned.
2024
- Error messages must match SQLite's parser byte-for-byte
2125
(`near "X": syntax error`, `unrecognized token: "X"`, `incomplete input`).
2226

internal/reference/README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
# Vendored SQLite sources (documentation only)
22

3-
These files are the grammar and tokenizer meyer is a port of, kept here so
4-
that the `parse.y` rule named in a parser comment can be read without a
5-
SQLite checkout. **Nothing in the repository processes them**: no parser
6-
generator runs, no build step reads them, and no test depends on them. They
7-
are reference material for humans, and the directory deliberately contains
3+
These files are the grammar, tokenizer and keyword table meyer is a port of,
4+
kept here so that the `parse.y` rule named in a parser comment can be read
5+
without a SQLite checkout. **No tool processes them**: no parser generator
6+
runs and no build step reads them, and the directory deliberately contains
87
no Go file, so it is not a package and `./...` does not reach it.
98

9+
Two tests do read them, to check transcriptions that would otherwise only
10+
ever be verified by hand:
11+
12+
- `token`'s tests rebuild the keyword table and the `%fallback` set from
13+
`mkkeywordhash.c` and `parse.y` and compare them with meyer's, resolved
14+
for the pinned build's feature flags.
15+
- `parser`'s tests check that every nonterminal in `parse.y` is named by a
16+
comment somewhere in the parser, which is how the repository's "every
17+
nontrivial parse function names its rule" rule is enforced.
18+
19+
Advancing the pin therefore surfaces a grammar or keyword change as a test
20+
failure rather than as a silent divergence.
21+
1022
| file | upstream path |
1123
|---|---|
1224
| `parse.y` | `src/parse.y` |
1325
| `tokenize.c` | `src/tokenize.c` |
26+
| `mkkeywordhash.c` | `tool/mkkeywordhash.c` |
1427

1528
Both come from SQLite 3.53.4, the release pinned in
1629
`cmd/regenerate-parse/main.go` and recorded in

0 commit comments

Comments
 (0)