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

A parsed node that can be included in the AST.

Nodes refer to each other via AstIndexs, see AstNode.

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

§args: Vec<AstIndex>

The arguments to pass to the function

§

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

§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

§

RangeFrom

A range without a defined end

Fields

§start: AstIndex

The start of the range

§

RangeTo

A range without a defined start

Fields

§end: AstIndex

The end of the range

§inclusive: bool

Whether or not the end of the range includes the end value itself

§

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

§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.

§

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

§target: AstIndex

The target of the assignment

§expression: AstIndex

The expression to be assigned

§

MultiAssign

A multiple-assignment expression

e.g. x, y = foo(), or foo, bar, baz = 1, 2, 3

Fields

§targets: Vec<AstIndex>

The targets of the assignment

§expression: AstIndex

The expression to be assigned

§

UnaryOp

A unary operation

Fields

§op: AstUnaryOp

The operator to use

§value: AstIndex

The value used in the operation

§

BinaryOp

A binary operation

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

§

If(AstIf)

An if expression

§

Match

A match expression

Fields

§expression: AstIndex

The expression that will be matched against

§arms: Vec<MatchArm>

The series of arms that match against the provided expression

§

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

Fields

§body: AstIndex

The loop’s body

§

While

A while loop

Fields

§condition: AstIndex

The condition for the while loop

§body: AstIndex

The body of the while loop

§

Until

An until expression

Fields

§condition: AstIndex

The condition for the until loop

§body: AstIndex

The body of the until loop

§

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

§expression: AstIndex

The expression that should be debugged

Trait Implementations§

source§

impl Clone for Node

source§

fn clone(&self) -> Node

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Node

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Node

source§

fn default() -> Node

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

impl Display for Node

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Node

source§

fn eq(&self, other: &Node) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Node

source§

impl StructuralPartialEq for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.