Skip to content

Nodes

opulse.expression.nodes

Expression trees whose operators are already resolved to :class:Operator records.

Unlike :mod:opulse.definition.ast (surface syntax, symbols only), these nodes point at concrete operators, so they can be evaluated directly. Use :func:to_ast to embed an expression into a definition.

iter_calls

iter_calls(node: Node) -> Iterator[Call]

Every call in node, children before parents.

defined_operators

defined_operators(node: Node) -> list[str]

Sorted func_ids of the defined operators applied in node, one entry per application.

map_operators

map_operators(
    node: Node, swap: Callable[[Operator], Operator]
) -> Node

Rebuild node with every operator replaced by swap(operator).

literal_form

literal_form(node: Node, registry) -> Node

Write every negative number atom as unary minus of its magnitude (spec section 7).

Expression trees must be in this form before they are evaluated, so that the evaluator and the reference interpreter count the same negation (review finding).

to_dict

to_dict(node: Node) -> dict

JSON form compatible with the legacy tree field.

from_ast

from_ast(node: Expr, registry) -> Node

Resolve a parsed expression against registry.