Expand description
DuckDB’s grammar, compiled to a table the matcher walks.
@generated by cargo xtask gen-grammar from the vendored grammar. Do not edit.
cargo xtask gen-grammar --check runs in the gate and fails if this file and the
grammar disagree.
NODES and FIRST are parallel. A node is twelve bytes and its FIRST set is eight
bytes at the same index, so deciding whether an alternative can match the token in
hand reads only FIRST and never loads the node. CHILDREN holds the child lists of
sequences and choices, contiguous per node, so a sequence is a slice rather than a
chase. Rules are the only nodes that are not expanded in place, which is what keeps
the table finite in the face of a recursive grammar.
Every table carries #[rustfmt::skip], because the generator and rustfmt disagree
about NULLABLE, CHILDREN and SYMBOLS and something has to win. rustfmt packs an
array whose elements are short onto as many per line as fit, so cargo fmt rewrote
this file and then gen-grammar --check failed on it, with both halves of the gate
correct and the working tree unable to satisfy them at once. One element a line is the
better answer anyway: a packed array reflows a whole block of lines when one entry
changes, and the point of checking this file in is that a grammar bump is a diff
somebody reads. The attribute is on all six rather than the three, so that a change to
rustfmt’s width threshold cannot bring the disagreement back.
Constants§
- PROGRAM
- The root.
Programis what a whole script parses as. - TOP_
LEVEL_ STATEMENT - The other root upstream requires, for parsing one statement rather than a script.
Statics§
- CHILDREN
- The child lists of every sequence and choice, contiguous per node.
- FIRST
- What each node can start with, as a set of token keys. A superset, always: a bit that is set may still fail to match, and a bit that is clear cannot possibly match, which is the only direction a filter is allowed to be wrong in.
- NODES
- The nodes.
- NULLABLE
- Whether each node can match without consuming a token.
- RULES
- The rules, sorted by name so a lookup by name is a binary search and the table does not depend on the order the generator happened to walk the grammar.
- SYMBOLS
- Every literal that is not a word. Punctuation and operator spellings, matched against the token text, which is the only place the matcher looks at the query again.