Syntax.Parse.Build
Canonical AST construction for a parser: every spanned node a production creates goes through a named builder here, so the meaning of a span or a synthesis bit is encoded once instead of being re-decided at hundreds of record literals.
The span discipline these builders enforce, the one the compiler’s own exporter observes: a node’s span runs from its first token’s start to its last consumed token’s end; a delimiter widens the span of the node it wraps; a node the parser invents (the list a multi-index desugars to, the pieces of an interpolated string) is synthesized, and a piece that corresponds to no source text of its own is zero-width at the position it conceptually occupies.
Functions and Values
authored
authored : forall a. (a, Int, Int) -> Syntax.Ast.Sp(a)
An authored node covering [lo, hi): written by the user, spanned by its own tokens.
synthesized
synthesized : forall a. (a, Int, Int) -> Syntax.Ast.Sp(a)
A synthesized node covering [lo, hi): invented by the parser while desugaring an authored form, spanning the source it stands for.
zero_width
zero_width : forall a. (a, Int) -> Syntax.Ast.Sp(a)
A zero-width node at at: a piece that corresponds to no source text of its own, carrying the position it conceptually occupies.
widened
widened : forall a. (Syntax.Ast.Sp(a), Int, Int) -> Syntax.Ast.Sp(a)
Rewrap a node with a delimiter’s extent: parentheses and brackets widen the span of the node they enclose while the node itself is unchanged.
operands_span
operands_span : forall a b. (Syntax.Ast.Sp(a), Syntax.Ast.Sp(b)) -> Syntax.Source.Span
The span an infix application covers: from its left operand’s start to its right operand’s end.