Expand description
Grammar-based free-name extraction for Polydat expression text.
Consumers that need to know “which wire / param / coordinate
names does this expression reference?” — workload validators,
comprehension-source analysis, the YAML→Polydat fusion layer —
MUST go through this module rather than byte-scanning the
source text for {...} or identifier-shaped runs. Byte
scanning misclassifies bare wire references (concat(foo)),
function names, and string-literal contents; the grammar
resolves all three correctly because it parses the same
tokens the kernel compiler does.
The extractor is built on the canonical lexer + expression
parser (crate::lexer::lex +
crate::parser::parse_expression) so a reference is
recognised exactly when the compiler would treat it as one.
FieldAccess (base.vector) contributes its source name;
StringLit contributes the {name} interpolation references
it carries; function callee names are NOT references (they
resolve in the function registry, not the wire scope).
Functions§
- collect_
expr_ refs - Walk a parsed
Expr, inserting every free name reference intoout. The traversal mirrorscrate::validate::validate_expr’s reference-collection arm minus the diagnostics, so the two stay in lockstep about what counts as a reference. - collect_
string_ interpolation_ refs - Extract
{name}interpolation references from a string literal’s contents. Skips format specifiers ({:05},{:.2}) and non-identifier bodies. This is the string-interpolation grammar — the only place{name}is a reference inside a parsed Polydat expression. (Raw YAML template fields like an op’sprepared:use the same interpolation grammar but never reach the Polydat parser; the YAML-fusion layer appliescollect_string_interpolation_refsto those directly.) - referenced_
names - Parse
textas a single Polydat expression and return the set of free names it references — wire/param/coordinate identifiers,FieldAccesssource names, and{name}interpolation references inside string literals. Function callee names are excluded (they resolve in the function registry). - try_
referenced_ names - Like
referenced_namesbut returnsErrwith the lexer/parser diagnostic whentextis not a single valid Polydat expression. Use when a parse failure should surface to the operator rather than silently yield no references.