math_spec.expansion
Named sub-expressions and macros, expanded into the core AST before anything reads the expression.
expand(node, schema, context, *, shadow=frozenset(), inlined=None)
#
Expand all named sub-expressions and macro calls under node.
A comparison stays a comparison and an arithmetic node stays arithmetic.
| 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. |
inlined
|
Where given, collects the name of every named expression inlined. |
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, *, inlined=None)
#
Parse text and expand named sub-expressions and macros to core AST.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The expression as the file wrote it.
TYPE:
|
schema
|
Where names and macros are declared.
TYPE:
|
context
|
What an error names.
TYPE:
|
inlined
|
Where given, every named expression inlined on the way is added to it — the ones a reference reaches through another entry or a macro included. |
Source code in src/math_spec/expansion.py
parse_template(name, macro, context)
#
Parse a macro template, rejecting comparisons.
read_by_the_math(schema)
#
The named expressions the math reads: every entry the objective or a constraint inlines, transitively.
Decided by expanding those two positions alone: a bound and a where
name no entry, and a piecewise link's expression reaches here through the
constraints its expansion emits. The rest of the expressions: section
is read back after a solve and never fed to one
(:attr:math_spec.program.ExpressionDeclaration.in_math).