Expand description
From the parse tree to the AST.
This is the one module that reads rule names out of the vendored grammar, and that is deliberate
containment: an upstream bump that renames a rule breaks a match arm here and nothing else in
the repository. spec/04-architecture.md section 4.5 says this transformer is ours and has to
be total over the rule table, and total is the load bearing word. Every rule reaches a defined
answer. For the ones this milestone covers that answer is an AST node, and for the rest it is a
Not implemented error naming the construct, which is what DuckDB itself answers for syntax it
parses and does not support. There is no arm that panics and none that silently drops a clause,
because a dropped clause is a wrong answer and a wrong answer is worse than an error.
The mechanism that makes it tractable is the default arm. Two thirds of the parse tree is the
expression precedence chain, twenty rules of the form X <- Y Tail* that exist to make the
grammar unambiguous and that carry no meaning once it has been parsed. Rather than name all
twenty, the expression walker handles the case where a rule matched something interesting and
otherwise descends through any node with exactly one child. That is not a shortcut. It is the
statement that a rule with one child said nothing, which is true of every chain link, and it
means the twenty first precedence level upstream adds costs us nothing.