Module placeholders
Expand description
Positional-placeholder scan over a query block’s raw SQL body.
This is a lexical scan, not a SQL parser — deliberately, and the
design (docs/design/declarative-custom-query.md §2) prices the
alternative: knowing a $N’s type requires preparing the statement
against a live catalogue, which would make cratestack-macros need a
database connection at macro-expansion time for the first time ever.
Knowing a $N’s position needs none of that, and position is all
the two checks in cratestack-parser’s validate/queries.rs need:
no reference beyond the declared parameter count, and no declared
parameter left unreferenced.
It does step over the spans Postgres itself reads as text — string
literals, dollar-quoted bodies, quoted identifiers and comments (see
[skip]) — because not doing so does not merely miss checks, it
falsely rejects valid SQL. That regression was real and measured
in cratestack#867’s review; [skip]’s module doc has the numbers and
the reasoning for why a lexer is on the right side of the line design
§3 draws.
Functions§
- scan_
sql_ placeholders - Every distinct
Nin a$Ntoken appearing insqlas an actual parameter reference, ascending.