pub enum Node {
Show 51 variants
Null,
Nested(AstIndex),
Id(ConstantIndex, Option<AstIndex>),
Meta(MetaKeyId, Option<ConstantIndex>),
Chain((ChainNode, Option<AstIndex>)),
BoolTrue,
BoolFalse,
SmallInt(i16),
Int(ConstantIndex),
Float(ConstantIndex),
Str(AstString),
List(AstVec<AstIndex>),
Tuple {
elements: AstVec<AstIndex>,
parentheses: bool,
},
TempTuple(AstVec<AstIndex>),
Range {
start: AstIndex,
end: AstIndex,
inclusive: bool,
},
RangeFrom {
start: AstIndex,
},
RangeTo {
end: AstIndex,
inclusive: bool,
},
RangeFull,
Map {
entries: AstVec<AstIndex>,
braces: bool,
},
MapEntry(AstIndex, AstIndex),
Self_,
MainBlock {
body: AstVec<AstIndex>,
local_count: usize,
},
Block(AstVec<AstIndex>),
Function(Function),
FunctionArgs {
args: AstVec<AstIndex>,
variadic: bool,
output_type: Option<AstIndex>,
},
Import {
from: AstVec<AstIndex>,
items: Vec<ImportItem>,
},
Export(AstIndex),
Assign {
target: AstIndex,
expression: AstIndex,
let_assignment: bool,
},
MultiAssign {
targets: AstVec<AstIndex>,
expression: AstIndex,
let_assignment: bool,
},
UnaryOp {
op: AstUnaryOp,
value: AstIndex,
},
BinaryOp {
op: AstBinaryOp,
lhs: AstIndex,
rhs: AstIndex,
},
If(AstIf),
Match {
expression: AstIndex,
arms: AstVec<AstIndex>,
},
MatchArm {
patterns: AstVec<AstIndex>,
condition: Option<AstIndex>,
expression: AstIndex,
},
Switch(AstVec<AstIndex>),
SwitchArm {
condition: Option<AstIndex>,
expression: AstIndex,
},
Ignored(Option<ConstantIndex>, Option<AstIndex>),
PackedId(Option<ConstantIndex>),
PackedExpression(AstIndex),
For(AstFor),
Loop {
body: AstIndex,
},
While {
condition: AstIndex,
body: AstIndex,
},
Until {
condition: AstIndex,
body: AstIndex,
},
Break(Option<AstIndex>),
Continue,
Return(Option<AstIndex>),
Try(AstTry),
Throw(AstIndex),
Yield(AstIndex),
Debug {
expression_string: ConstantIndex,
expression: AstIndex,
},
Type {
type_index: ConstantIndex,
allow_null: bool,
},
}Expand description
Variants§
Null
The null keyword
Nested(AstIndex)
A single expression wrapped in parentheses
Id(ConstantIndex, Option<AstIndex>)
An identifier, and optionally the type hint node
Meta(MetaKeyId, Option<ConstantIndex>)
A meta identifier, e.g. @display or @test my_test
Chain((ChainNode, Option<AstIndex>))
A chained expression, and optionally the node that follows it in the chain
BoolTrue
The true keyword
BoolFalse
The false keyword
SmallInt(i16)
An integer in the range -255..=255
Int(ConstantIndex)
An integer outside of the range -255..=255
Float(ConstantIndex)
A float literal
Str(AstString)
A string literal
List(AstVec<AstIndex>)
A list literal
E.g. [foo, bar, 42]
Tuple
A tuple literal
E.g. (foo, bar, 42)
Fields
TempTuple(AstVec<AstIndex>)
A temporary tuple
Used in contexts where the result won’t be exposed directly to the user, e.g.
x, y = 1, 2: x and y are indexed from the temporary tuple.match foo, bar...: foo and bar will be stored in a temporary tuple for comparison.
Range
A range with a defined start and end
Fields
RangeFrom
A range without a defined end
RangeTo
A range without a defined start
Fields
RangeFull
The range operator without defined start or end
Used when indexing a list or tuple, and the full contents are to be returned.
Map
A map literal, containing a series of key/value entries
Fields
MapEntry(AstIndex, AstIndex)
A key/value pair representing a Map entry.
Keys will either be Id, String, or Meta nodes.
Self_
The self keyword
MainBlock
The main block node
Typically all ASTs will have this node at the root.
Fields
Block(AstVec<AstIndex>)
A block node
Used for indented blocks that share the context of the frame they’re in, e.g. if expressions, arms in match or switch expressions, loop bodies.
Function(Function)
A function node
FunctionArgs
A function’s arguments
Fields
Import
An import expression
E.g. from foo.bar import baz, 'qux'
Fields
from: AstVec<AstIndex>Where the items should be imported from
An empty list here implies that import without from has been used.
items: Vec<ImportItem>The series of items to import
An empty list here implies that a * wildcard import was used.
Export(AstIndex)
An export expression
The export item will be a map literal, with each map entry added to the exports map
Assign
An assignment expression
Used for single-assignment, multiple-assignment is represented by Node::MultiAssign.
Fields
MultiAssign
A multiple-assignment expression
E.g. x, y = foo(), or foo, bar, baz = 1, 2, 3
Fields
UnaryOp
A unary operation
BinaryOp
A binary operation
Fields
op: AstBinaryOpThe operator to use
If(AstIf)
An if expression
Match
A match expression
Fields
MatchArm
An arm of a Self::Match expression
Fields
patterns: AstVec<AstIndex>A series of match patterns
If patterns is empty then else is implied, and should always appear as the last arm.
Switch(AstVec<AstIndex>)
A switch expression
SwitchArm
An arm of a Self::Switch expression
Fields
Ignored(Option<ConstantIndex>, Option<AstIndex>)
A _-prefixed identifier
Used as a placeholder for unused function arguments or unpacked values, or as an ignored match-all in match expressions.
Comes with an optional name (e.g. _foo will have foo stored as a constant),
and an optional type hint.
PackedId(Option<ConstantIndex>)
Used when capturing variadic arguments, and when unpacking list or tuple arguments.
The id is optional, e.g. f = |(..., last)| last
PackedExpression(AstIndex)
Used when an argument in a function call needs to be unpacked
e.g. f(args...)
The argument can be any expression, e.g. f (1..100).take(3)...
For(AstFor)
A for loop
Loop
A loop expression
While
A while loop
Fields
Until
An until expression
Fields
Break(Option<AstIndex>)
The break keyword, with optional break value
Continue
The continue keyword
Return(Option<AstIndex>)
A return expression, with optional return value
Try(AstTry)
A try expression
Throw(AstIndex)
A throw expression
Yield(AstIndex)
A yield expression
Debug
A debug expression
Fields
expression_string: ConstantIndexThe stored string of the debugged expression to be used when printing the result
Type
A type hint
E.g. let x: Number = 0
^~~ This is the beginning of the type hint
Fields
type_index: ConstantIndexThe expected type as a string