Skip to content

astero.python.emit

A Python expression emitter whose brackets come from the declared precedence table rather than from the templates.

astero.python.emit

A Python expression emitter, with brackets derived rather than written.

The templates say what each production looks like. None of them says when a subexpression needs brackets: child asks needs_parens with the declared precedence, and that is the only place the question is answered.

The oracle is a round trip. Emit an expression, parse the result, and compare the trees. tests/b_integration/test_emit_roundtrip.py runs it over every expression in the standard library.

child

child(
    node: expr, outer: Level, *, on_right: bool = False
) -> Doc

Emit node in a position of binding power outer, bracketing if needed.

The one place brackets are decided. Every template calls this and none of them knows the rule.

expr

expr(node: expr) -> Doc

A document for node, by production.

block

block(body: list[stmt]) -> Doc

An indented suite, one statement per line.

stmt

stmt(node: stmt) -> Doc

A document for one statement.

emit

emit(node: expr) -> str

Source text for an expression.

emit_module

emit_module(node: Module) -> str

Source text for a module.