Skip to main content

Module ast

Module ast 

Source
Expand description

Python abstract syntax tree.

Faithful to CPython’s surface grammar as far as pythonrs lowers it today: every node here has a direct lowering in compiler.rs. Unlike Ruby, Python is statement-oriented — most control flow is a Stmt that yields no value — so the tree separates Stmt (blocks of these form suites) from Expr.

Structs§

Alias
An import alias: name [as asname].
Comprehension
One (target, iter, ifs) clause of a comprehension.
ExceptHandler
One except clause of a try.
Keyword
A keyword argument at a call site: name=value, or **mapping when name is None.
Loc
A node’s extent as CPython’s AST records it: 1-based lines and 0-based UTF-8 BYTE columns, end exclusive (lineno, col_offset, end_lineno, end_col_offset). The compiler raises its pattern SyntaxErrors at this extent, and compiler_error reports col_offset + 1 — a byte column — as the exception’s offset.
MatchCase
One case pattern [if guard]: body of a match.
Params
A formal-parameter list for a def/lambda.
Pattern
A match pattern (PEP 634): its shape and where it sits in the source.
Span
A source span for traceback carets: character columns within a 1-based line. line == 0 marks “no span” (synthetic/desugared nodes). When anchor_end > anchor_start, the [anchor_start, anchor_end) sub-range renders the secondary caret ^ and the rest of [start, end) renders the primary caret ~ — CPython’s ~^~ binary-op and ~~~^^^ subscript/call anchoring. With no anchor the whole [start, end) renders ^.
Stmt
A statement plus its 1-based source line (for tracebacks and DAP markers).
TypeParam
One PEP 695 type parameter: T, *Ts or **P.
WithItem
One with item: context_expr [as optional_vars].

Enums§

BinOp
A binary arithmetic/bit operator (Python a <op> b). Comparison and boolean operators are separate (Compare, BoolOp) because Python chains them.
BoolOp
A boolean short-circuit operator.
CmpOp
A comparison operator (one link of a Compare chain).
Expr
A Python expression.
FStrPart
A formatted-string segment (f"...").
PatternKind
The shape of a Pattern.
StmtKind
A Python statement.
TypeParamKind
Which typing object a TypeParam creates.
UnOp
A unary operator.