Enum koto_parser::Node
source · pub enum Node {
Show 46 variants
Null,
Nested(AstIndex),
Id(ConstantIndex),
Meta(MetaKeyId, Option<ConstantIndex>),
Lookup((LookupNode, Option<AstIndex>)),
NamedCall {
id: ConstantIndex,
args: Vec<AstIndex>,
},
BoolTrue,
BoolFalse,
SmallInt(i16),
Int(ConstantIndex),
Float(ConstantIndex),
Str(AstString),
List(Vec<AstIndex>),
Tuple(Vec<AstIndex>),
TempTuple(Vec<AstIndex>),
Range {
start: AstIndex,
end: AstIndex,
inclusive: bool,
},
RangeFrom {
start: AstIndex,
},
RangeTo {
end: AstIndex,
inclusive: bool,
},
RangeFull,
Map(Vec<(MapKey, Option<AstIndex>)>),
Self_,
MainBlock {
body: Vec<AstIndex>,
local_count: usize,
},
Block(Vec<AstIndex>),
Function(Function),
Import {
from: Vec<IdOrString>,
items: Vec<ImportItem>,
},
Export(AstIndex),
Assign {
target: AstIndex,
expression: AstIndex,
},
MultiAssign {
targets: Vec<AstIndex>,
expression: AstIndex,
},
UnaryOp {
op: AstUnaryOp,
value: AstIndex,
},
BinaryOp {
op: AstBinaryOp,
lhs: AstIndex,
rhs: AstIndex,
},
If(AstIf),
Match {
expression: AstIndex,
arms: Vec<MatchArm>,
},
Switch(Vec<SwitchArm>),
Wildcard(Option<ConstantIndex>),
Ellipsis(Option<ConstantIndex>),
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,
},
}
Expand description
Variants§
Null
The null
keyword
Nested(AstIndex)
A single expression wrapped in parentheses
Id(ConstantIndex)
An identifer
Meta(MetaKeyId, Option<ConstantIndex>)
A meta identifier, e.g. @display
or @test my_test
Lookup((LookupNode, Option<AstIndex>))
A lookup node, and optionally the node that follows it in the lookup chain
NamedCall
A parentheses-free call on a named id, e.g. foo 1, 2, 3
Calls with parentheses or on temporary values are parsed as Lookups
Fields
id: ConstantIndex
The id of the function to be called
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(Vec<AstIndex>)
A list literal
e.g. [foo, bar, 42]
Tuple(Vec<AstIndex>)
A tuple literal
e.g. (foo, bar, 42)
Note that this is also used for implicit tuples, e.g. in x = 1, 2, 3
TempTuple(Vec<AstIndex>)
A temporary tuple
Used in contexts where the result won’t be exposed directly to the use, e.g.
x, y = 1, 2
- here 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(Vec<(MapKey, Option<AstIndex>)>)
A map literal, with a series of keys and values
Values are optional for inline maps.
Self_
The self
keyword
MainBlock
The main block node
Typically all ASTs will have this node at the root.
Fields
Block(Vec<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 experssions, loop bodies
Function(Function)
A function node
Import
An import expression
e.g. `from foo.bar import baz, ‘qux’
Fields
from: Vec<IdOrString>
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
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: AstBinaryOp
The operator to use
If(AstIf)
An if expression
Match
A match expression
Fields
Switch(Vec<SwitchArm>)
A switch expression
Wildcard(Option<ConstantIndex>)
A _
identifier
Used as a placeholder for unused function arguments or unpacked values, or as a wildcard in match expressions.
Comes with an optional name, e.g. _foo
will have foo
stored as a constant.
Ellipsis(Option<ConstantIndex>)
The ...
operator
Used when capturing variadic arguments, and when unpacking list or tuple values.
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: ConstantIndex
The stored string of the debugged expression to be used when printing the result