Imported from nikita-volkov/postgresql-syntax (
AGENTS.md). Install upstream withnpx skills add nikita-volkov/postgresql-syntax. Copyright stays with the author.
References
- Grammar file (primary source of info): https://github.com/postgres/postgres/blob/c12c101b0846b1e6488f2dc986a852fbc6bf2e3b/src/backend/parser/gram.y
- Keywords file: https://github.com/postgres/postgres/blob/c12c101b0846b1e6488f2dc986a852fbc6bf2e3b/src/include/parser/kwlist.h
- Scanner: https://github.com/postgres/postgres/blob/c12c101b0846b1e6488f2dc986a852fbc6bf2e3b/src/backend/parser/scan.l
- Other files (for extra info): https://github.com/postgres/postgres/tree/c12c101b0846b1e6488f2dc986a852fbc6bf2e3b/src/backend/parser
Arbitrary instances for Ast types
Each PostgresqlSyntax.Ast.* module's instance Qc.Arbitrary <Type> must terminate at size 0 and stay proportionally bounded as size grows. Don't reach for blanket Qc.scale/Qc.resize guesswork on a whole generator or oneof block - apply Gens.downscale (from PostgresqlSyntax.Helpers.Gens) individually, per field, using this rule:
- An
arbitrarycall gets wrapped inGens.downscaleif and only if the value it produces is:- the type being defined itself (direct self-recursion) - including nested inside a container like
Maybe X,[X],NonEmpty X, orEither X Y, in which case the whole container-producing call gets oneGens.downscale, not each element, OR - a type imported into that module via
import {-# SOURCE #-} ....
- the type being defined itself (direct self-recursion) - including nested inside a container like
- Every other field (plain, non-recursive, non-
SOURCEtypes) stays plainQc.arbitrary/arbitrary- no downscaling. - This holds even for fields whose type is only mutually recursive with the type being defined through an ordinary (non-
SOURCE) import: that recursion is already terminated on the other side of the cycle, at whichever module has theSOURCEimport breaking it. Downscaling both sides would over-shrink. - Every
Arbitraryinstance must terminate at size 0 - i.e. escape every recursive strongly-connected component and yield a small/leaf value, not an unbounded random walk. Use theGens.terminatingMaybehelper (also inPostgresqlSyntax.Helpers.Gens) forMaybe Xfields whereXis self-recursive orSOURCE-imported - it forcesNothingat small sizes instead of relying on the defaultMaybeinstance's non-size-awarefrequency. - Reference implementations:
PostgresqlSyntax.Ast.AExpr,PostgresqlSyntax.Ast.AnyOperator,PostgresqlSyntax.Ast.ExprList,PostgresqlSyntax.Ast.CaseExpr.