Enum koto_parser::Node [−][src]
pub enum Node {
Show 47 variants
Empty,
Nested(AstIndex),
Id(ConstantIndex),
Meta(MetaKeyId, Option<ConstantIndex>),
Lookup((LookupNode, Option<AstIndex>)),
NamedCall {
id: ConstantIndex,
args: Vec<AstIndex>,
},
BoolTrue,
BoolFalse,
Number0,
Number1,
Int(ConstantIndex),
Float(ConstantIndex),
Str(AstString),
Num2(Vec<AstIndex>),
Num4(Vec<AstIndex>),
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>)>),
MainBlock {
body: Vec<AstIndex>,
local_count: usize,
},
Block(Vec<AstIndex>),
Function(Function),
Import {
items: Vec<Vec<ImportItemNode>>,
from: Vec<ImportItemNode>,
},
Assign {
target: AssignTarget,
op: AssignOp,
expression: AstIndex,
},
MultiAssign {
targets: Vec<AssignTarget>,
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,
Ellipsis(Option<ConstantIndex>),
For(AstFor),
Loop {
body: AstIndex,
},
While {
condition: AstIndex,
body: AstIndex,
},
Until {
condition: AstIndex,
body: AstIndex,
},
Break,
Continue,
Return(Option<AstIndex>),
Try(AstTry),
Throw(AstIndex),
Yield(AstIndex),
Debug {
expression_string: ConstantIndex,
expression: AstIndex,
},
}
Expand description
Variants
Empty
An Empty node, used for ()
empty expressions
Nested(AstIndex)
Tuple Fields
0: AstIndex
A single expression wrapped in parentheses
Id(ConstantIndex)
Tuple Fields
An identifer
Meta(MetaKeyId, Option<ConstantIndex>)
A meta identifier, e.g. @display
or @test my_test
Lookup((LookupNode, Option<AstIndex>))
Tuple Fields
0: (LookupNode, Option<AstIndex>)
A lookup node, and optionally the node that follows it in the lookup chain
NamedCall
Fields
id: ConstantIndex
The id of the function to be called
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
BoolTrue
The true
keyword
BoolFalse
The false
keyword
Number0
The integer 0
Number1
The integer 1
Int(ConstantIndex)
Tuple Fields
An integer literal
Float(ConstantIndex)
Tuple Fields
An float literal
Str(AstString)
Tuple Fields
0: AstString
A string literal
Num2(Vec<AstIndex>)
A num2
expression
e.g. num2 1
or num2 3, 4
Num4(Vec<AstIndex>)
A num4
expression
e.g. num4 1
, num4 1, 2, 3, 4
, etc.
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
Fields
start: AstIndex
The start of the range
end: AstIndex
The end of the range
inclusive: bool
Whether or not the end of the range includes the end value itself
e.g. 1..10
- a range from 1 up to but not including 10
e.g. 1..=10
- a range from 1 up to and including 10
A range with a defined start and end
RangeFrom
Fields
start: AstIndex
The start of the range
A range without a defined end
RangeTo
Fields
end: AstIndex
The end of the range
inclusive: bool
Whether or not the end of the range includes the end value itself
A range without a defined start
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.
MainBlock
Fields
local_count: usize
The number of locally assigned values in the main block
This tells the compiler how many registers need to be reserved for locally assigned values.
The main block node
Typically all ASTs will have this node at the root.
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)
Tuple Fields
0: Function
A function node
Import
Fields
items: Vec<Vec<ImportItemNode>>
The series of items to import
from: Vec<ImportItemNode>
Where the items should be imported from
An empty list here implies that import without from
has been used.
An import expression
Each import item is defined as a series of ImportItemNodes,
e.g. from foo.fun import baz.bar, caz.car.cax
Assign
Fields
target: AssignTarget
The target of the assignment
op: AssignOp
The operator to use, e.g. =
, +=
, etc.
expression: AstIndex
The expression to be assigned
An assignment expression
Used for single-assignment, multiple-assignment is represented by Node::MultiAssign.
MultiAssign
Fields
targets: Vec<AssignTarget>
The targets of the assignment
expression: AstIndex
The expression to be assigned
A multiple-assignment expression
e.g. x, y = foo()
, or foo, bar, baz = 1, 2, 3
UnaryOp
A unary operation
BinaryOp
Fields
op: AstBinaryOp
The operator to use
lhs: AstIndex
The “left hand side” of the operation
rhs: AstIndex
The “right hand side” of the operation
A binary operation
If(AstIf)
Tuple Fields
0: AstIf
An if expression
Match
Fields
expression: AstIndex
The expression that will be matched against
A match expression
Switch(Vec<SwitchArm>)
A switch expression
Wildcard
The _
operator
Used as a placeholder for unused function arguments or ignored unpacked values.
Ellipsis(Option<ConstantIndex>)
Tuple Fields
0: Option<ConstantIndex>
The ...
operator
Used when capturing variadic arguments, and when unpacking list values.
For(AstFor)
Tuple Fields
0: AstFor
A for
loop
Loop
Fields
body: AstIndex
The loop’s body
A loop
expression
While
A while
loop
Until
An until
expression
Break
The break keyword
Continue
The continue keyword
Return(Option<AstIndex>)
A return expression, with optional return value
Try(AstTry)
Tuple Fields
0: AstTry
A try expression
Throw(AstIndex)
Tuple Fields
0: AstIndex
A throw expression
Yield(AstIndex)
Tuple Fields
0: AstIndex
A yield expression
Debug
Fields
expression_string: ConstantIndex
The stored string of the debugged expression to be used when printing the result
expression: AstIndex
The expression that should be debugged
A debug expression
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Node
impl UnwindSafe for Node
Blanket Implementations
Mutably borrows from an owned value. Read more