Skip to main content

Module rules

Module rules 

Source
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 is the whole grammar. A node is twenty four bytes and carries its FIRST set and its nullable bit, so deciding whether an alternative can match the token in hand and then walking it read the same twenty four bytes. A Rule node carries the index of its body as well as the index of the rule, so entering a rule never reads RULES. 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 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 four rather than the two, so that a change to rustfmt’s width threshold cannot bring the disagreement back.

Constants§

PROGRAM
The root. Program is 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.
NODES
The nodes. Each one carries what it can start with, as a set of token keys, and that set is 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. Node::NULLABLE in flags says the node can match nothing at all, and a node like that is never filtered out.
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.