Pure Go port of pg_query_go. Read PLAN.md first — it is the contract.
Pin: libpg_query 18.0.0 (PostgreSQL 18.4, patched). No cgo anywhere in
the main module; the only module allowed to link pg_query_go (cgo) is
oracle/, and only cmd/regenerate/cmd/difftest ever run it.
go run ./cmd/next-test— picks the nexttodocase fromparser/testdata/*/.- Implement the production in
internal/parse/(or lexer rule ininternal/lexer/), with an attribution comment naming thegram.y/scan.lrule (// gram.y: simple_select). go test ./parser -run TestCorpus -check-parse— runs thetodocases; newly passing cases are removed from themetadata.jsonsidecars automatically. Commit the sidecar diff with the code.go test ./...must stay green; a case that regresses from passing to failing is a hard failure, never a new todo.
- Expected outputs are never edited by hand. Goldens come from
cmd/regenerate(the pinned oracle) or not at all. - Generated files (
ast/pg_query.pb.go,aliases.go,internal/lexer/keywords.go,internal/plpgsql/tables.go) are only ever written bycmd/generate. - The public API mirrors pg_query_go exactly; consumers must migrate by
changing one import path. Never rename, add, or remove exported symbols
without checking pg_query_go v6.2.2. There are two deliberate additions,
both in the
parsersubpackage (PLAN.md § 1):ParseToTree, the tree without the protobuf round trip the cgo boundary forces upstream, andParseFile, that tree plus the commentsbase_yylexdrops. - Location fields must byte-match the reference; when in doubt, check which
@Nthegram.yaction uses.
internal/reference/— pinnedgram.y,scan.l,parser.c,kwlist.h(docs only). Thebase_yylextoken-merge filter is inparser.c.srcdata/— vendored libpg_query metadata JSON +pg_query.proto(generator inputs).parser/testdata/<suite>/*.test— corpus: cases split by==, input and expectation split by--.metadata.jsonsidecar per file trackstodo.oracle/— separate go module, cgo, never imported by the main module.
go run ./cmd/generate -aliases -keywords— pure Go, always safe.go run ./cmd/generate -proto— requiresprotoc+protoc-gen-go.go run ./cmd/regenerate -libpg-query <checkout> -pg-query-go <checkout>— builds the cgo oracle, rewritesparser/testdatafrom scratch. Output must be byte-identical run-to-run.