Skip to content

Ast

opulse.definition.ast

Typed syntax tree of the definition language, plus rendering back to text.

Generators build these nodes directly and call :func:render_definition; the parser turns text back into the same nodes. Code generation, complexity metrics and the reference interpreter all walk this tree, so none of them depend on lark.

Operator applications store only the surface form (symbol, arity, position). Resolving the symbol to a concrete operator is done later against a registry.

Num dataclass

A non-negative integer literal. Negative constants are written as the prefix - operator applied to a literal, which costs one operation. base only affects how the literal is written (a base-marked numeral).

Literal dataclass

A boolean, string, or list literal.

Search dataclass

Least index from zero through bound satisfying condition.

Branch dataclass

expr, if condition / expr, else / bare expr (both fields None).

negate

negate(value: int) -> Expr

The constant value as an expression (- 5 for negative values).

iter_applications

iter_applications(
    node: Expr | Condition,
) -> Iterator[Apply]

All operator applications inside node, children before parents.

condition_operands

condition_operands(node: Condition) -> Iterator[Expr]

The expressions compared inside a condition.

branch_variables

branch_variables(branch: Branch) -> set[str]

Variables read by a branch, in its body or its condition.

decimal_literal

decimal_literal(value: int) -> str

Write an unbounded decimal integer without Python's decimal digit cap.

render_expr

render_expr(
    node: Expr,
    symbols: Symbols,
    top: bool = True,
    numerals=None,
) -> str

Render with every operator application parenthesised except the outermost.

An application with three or more arguments is written in call form, ⊕(x, y, z). It delimits itself, so it is never parenthesised, and its arguments are written as at the top.