Enum koto_parser::Node[][src]

pub enum Node {
Show 47 variants Empty, Nested(AstIndex), Id(ConstantIndex), Meta(MetaKeyIdOption<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

A parsed node that can be included in the AST.

Nodes refer to each other via AstIndexs, see AstNode.

Variants

Empty

An Empty node, used for () empty expressions

Nested(AstIndex)

Tuple Fields

A single expression wrapped in parentheses

Id(ConstantIndex)

Tuple Fields

An identifer

Meta(MetaKeyIdOption<ConstantIndex>)

Tuple Fields

A meta identifier, e.g. @display or @test my_test

Lookup((LookupNode, Option<AstIndex>))

Tuple Fields

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

args: Vec<AstIndex>

The arguments to pass to the function

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

A string literal

Num2(Vec<AstIndex>)

Tuple Fields

A num2 expression

e.g. num2 1 or num2 3, 4

Num4(Vec<AstIndex>)

Tuple Fields

A num4 expression

e.g. num4 1, num4 1, 2, 3, 4, etc.

List(Vec<AstIndex>)

Tuple Fields

A list literal

e.g. [foo, bar, 42]

Tuple(Vec<AstIndex>)

Tuple Fields

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>)

Tuple Fields

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>)>)

Tuple Fields

A map literal, with a series of keys and values

Values are optional for inline maps.

MainBlock

Fields

body: Vec<AstIndex>

The main block’s body as a series of expressions

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>)

Tuple Fields

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

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

Fields

op: AstUnaryOp

The operator to use

value: AstIndex

The value used in the operation

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

arms: Vec<MatchArm>

The series of arms that match against the provided expression

A match expression

Switch(Vec<SwitchArm>)

Tuple Fields

A switch expression

Wildcard

The _ operator

Used as a placeholder for unused function arguments or ignored unpacked values.

Ellipsis(Option<ConstantIndex>)

Tuple Fields

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

Fields

condition: AstIndex

The condition for the while loop

body: AstIndex

The body of the while loop

A while loop

Until

Fields

condition: AstIndex

The condition for the until loop

body: AstIndex

The body of the until loop

An until expression

Break

The break keyword

Continue

The continue keyword

Return(Option<AstIndex>)

Tuple Fields

A return expression, with optional return value

Try(AstTry)

Tuple Fields

0: AstTry

A try expression

Throw(AstIndex)

Tuple Fields

A throw expression

Yield(AstIndex)

Tuple Fields

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.