Expand description
Recursive descent parser for the Polydat DSL.
Parses a token stream (from the lexer) into an AST.
Infix arithmetic expressions (+, -, *, /, %, ^) are
handled by a Pratt (precedence-climbing) parser that produces
Expr::BinOp nodes, later desugared by the compiler into
function calls.
§String interpolation
String literals containing { … } placeholders
(polydat_grammar.md §9) are desugared to a printf call over
the placeholder bodies. The bodies are parsed as full Polydat
expressions via parse_expression — same entry the rest of
the language uses — so anything that can appear on a binding
right-hand side can appear inside a placeholder.
Examples:
"hello"— no placeholders →Expr::StringLit("hello")."{name}"— bare identifier →printf("{}", name)."x={a + b}"— infix expression →printf("x={}", a + b)."{format_u64(hash(cycle), 10)}@example.com"— nested call →printf("{}@example.com", format_u64(hash(cycle), 10))."{row.id}"— field access →printf("{}", row.id)."{{literal braces}}"— escaped → stays aStringLit(printf emits{/}from{{/}}at format time)."x={:05}"— printf format spec, not a Polydat expression → stays aStringLit; the user is calling printf by hand."missing close {abc"— unterminated placeholder → stays aStringLit.
The desugaring is pure syntactic sugar. The resulting printf
call goes through the standard binding/assembly path: each
placeholder expression compiles to a node, the printf node
ingests their outputs as wires, and at evaluation time
Value::to_display_string() renders each input into its slot.
No special runtime support is needed beyond printf.
Functions§
- binary_
operator - The binary operator a token spells, if it spells one.
- binding_
power - The binding powers
(left, right)of a binary operator: the one precedence table of the language (polydat_grammar.md §6.1), whose levelsparse_expr_bplists. Expressions and comprehensionwherepredicates (crate::comprehension::predicate) both parse with it. A higher power binds tighter;left < rightassociates to the left andleft > rightto the right. The unary operators-and!bind tighter than every binary operator: each applies to the atom after it. - for_
source_ from_ text - Classify and parse the text after
for. - parse
- Parse a token stream into a PolydatFile AST.
- parse_
expression - Parse a token stream as a single Polydat expression.
- parse_
with_ tile_ defaults parsereading every tile that names no delimiters or sigil of its own undertile_defaults.