Skip to content

astero.python.precedence

Python's operator precedence, and the three questions that read it. The bracketing rule is language-agnostic and lives in emit; what binds tighter than what is a fact about Python.

astero.python.precedence

Python's operator precedence, and the three questions that read it.

astero.emit holds the document algebra and the bracketing rule: Level, Assoc and needs_parens work on any language. What binds tighter than what is a fact about Python, so it lives here rather than there.

Split out when the package grew an astero.python — the tables had been sitting in the generic module since the emitter was written, which is the same misplacement this library exists to complain about.

abuts_badly

abuts_badly(receiver: expr) -> bool

Whether a . directly after receiver would lex as part of it.

Precedence decides grouping. It does not decide token separation, and 3531.to_bytes(...) is a syntax error because 3531. lexes as a float. A second, much smaller declaration covers that: the two questions are independent and an emitter needs both.

parser_flattens

parser_flattens(parent: expr, child: expr) -> bool

Whether reparsing would merge child into parent.

a and (b and c) parses as one three-value BoolOp, so emitting it without brackets loses the tree even though it keeps the meaning. Like abuts_badly, this is a fact about the parser that no precedence table states, and it is the second entry in that small second declaration.

level_of

level_of(node: expr) -> Level

The binding power of an expression, from the declared table.