Commit dc443db
committed
Add the SQL renderer, AST dump, round-trip property and snapshots
The second half of PLAN.md's answer to "SQLite has no parse-tree oracle".
Accept/reject conformance cannot see a dropped clause or an operator
associated the wrong way, so two layers stand in for upstream goldens:
- ast.String/ast.Statements render a tree back to SQL. Not a formatter,
and no promises beyond re-parseability. Parenthesisation needs no
precedence logic, because the parser keeps explicit parentheses as
ParenExpr nodes.
- internal/dump renders a node reflectively, so it cannot fall behind the
node set: a field added to a node shows up in the next snapshot diff
whether or not anyone remembered. Two option sets — everything, for
snapshots, and shape-only for comparisons, which drops the spans and
Raw text a round trip is entitled to change.
- TestRoundTrip runs parse/render/parse over all 20,815 accepting corpus
cases and compares the trees, then checks that rendering is idempotent.
- TestASTSnapshots covers a hand-written tour of the node set under
parser/testdata/ast, with -update to rewrite the goldens.
Two things this found:
- IndexedColumn recorded that a COLLATE was present but not which
collation, so "FOREIGN KEY(b COLLATE nocase DESC)" lost the name.
- Three nodes built their Span from a composite literal that also called
the parse function for their last child, so the span ended before the
child began. Go does not order those evaluations.
Enum types gained String methods, so a snapshot diff names what changed
instead of printing an integer.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JzBeCg7rjweVW3uGPg5G7T1 parent 6f3292a commit dc443db
20 files changed
Lines changed: 5840 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
50 | 65 | | |
51 | 66 | | |
52 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
152 | | - | |
153 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
0 commit comments