math_spec.expansion
Named sub-expressions and macros, both declared in the YAML and expanded into the AST before anything reads the expression.
There is no Python operator registry: the built-in set is closed, macros cover
composition, and math the language cannot say goes in a declared escape:
island (#38).
expand(node, schema, context='expression', *, shadow=frozenset())
#
Expand all named sub-expressions and macro calls under node.
Expansion never changes the shape of the root: a comparison stays a
comparison, an arithmetic node stays arithmetic. The overloads say so, so
callers holding an ArithmeticNode keep it across the call.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The parsed expression.
TYPE:
|
schema
|
Where names and macros are declared.
TYPE:
|
context
|
What an error names.
TYPE:
|
shadow
|
Names left as written even where a named expression has that name — a template's formals, checked without a call to bind them. |
Source code in src/math_spec/expansion.py
macro_signature(name, macro)
#
Human-readable call signature, for error messages.
parse_and_expand(text, schema, context='expression')
#
Parse text and expand named sub-expressions and macros to core AST.
parse_template(name, macro, context)
#
Parse a macro template, rejecting comparisons.