pub enum Statement {
Show 14 variants
Class(Class),
Annotated(Annotated),
Assign(Assign),
Function(Function),
Set {
place: Expr,
value: Expr,
},
Expr(Expr),
If {
condition: Expr,
then: Vec<Statement>,
otherwise: Option<Vec<Statement>>,
},
For {
counter: Ident,
bound: Expr,
body: Vec<Statement>,
},
While {
condition: Expr,
body: Vec<Statement>,
},
Break,
Return(Option<Expr>),
Comment(Doc),
Pass,
Verbatim(String),
}Expand description
One statement of a module or a class body.
Variants§
Class(Class)
A class definition.
Annotated(Annotated)
name: Type or name: Type = value — an annotated binding.
One node for a dataclass field, a Final constant and a bitset’s
bitfield: Python spells all three the same way, and a tree that
distinguished them would be recording the rule’s intent rather
than the syntax.
Assign(Assign)
name = value — a binding with no annotation.
What a type alias and an enumeration member take: RED = 0 inside
an enum.IntEnum is a member and RED: int = 0 is not, so the
two forms are not interchangeable.
Function(Function)
A function definition.
Set
place = value — a store into somewhere that already exists.
v.field = x, v[i] = x, zd_wire = 3. Distinct from
Statement::Assign for the reason the module documentation
gives: a binding introduces a name and a store does not, and only
the first of the two may appear where an enumeration member is
read off the class body.
Expr(Expr)
An expression evaluated for its effect.
What a call to the runtime is: w.write_u32(v.x). Python has no
(void) cast and no discarded-result diagnostic, so a value the
generated code reads and does not keep is written as the call and
nothing else.
If
if condition: ... [else: ...]
No elif. A chain is an else whose body is one more
Statement::If, which is what elif abbreviates and what the
codec walk builds; a separate arm would be a second spelling of
one tree.
Fields
For
for counter in range(bound): ...
A counted loop and not the general for x in y. The codec walk’s
CodecTarget::count_up asks for a count from zero and nothing
else; a tree that could hold any iterable would be recording a
loop this column never writes.
Fields
While
while condition: ...
Break
break.
Return(Option<Expr>)
return, with or without a value.
Comment(Doc)
A # comment on lines of its own.
Pass
pass.
A body has to hold something. A rule that produced an empty class emits this rather than leaving the renderer to notice, because a renderer that inserted it would be deciding what the tree says.
Verbatim(String)
@verbatim text, copied into the output unchanged — OMG IDL 4.2
§8.3.5.1 asks for the text “verbatim”, so raw lines and never a
comment. At the indentation of the suite it stands in.