pub struct ParseNode {
pub rule: u32,
pub start: u32,
pub end: u32,
pub first_child: u32,
pub next_sibling: u32,
}Expand description
One node of the parse tree. Twenty bytes.
Children are a linked list rather than a slice, because a node’s children are discovered one at a time and interleaved with the children of every other node being built at the same moment, so a contiguous list would need either a second pass or a per node vector. The list is built in order and read in order, which is the only access pattern the transformer has.
Terminals get no node. A keyword, a symbol and a literal are all recoverable from the token span of the rule that contains them, and giving each one a node would roughly triple the tree for information that is already in the token vector.
Fields§
§rule: u32Which rule this is, as an index into RULES.
start: u32The first token it covers.
end: u32One past the last token it covers.
first_child: u32Its first child, or NONE.
next_sibling: u32The next child of this node’s parent, or NONE.