Node

Enum Node 

Source
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

A parsed node that can be included in the AST.

Nodes refer to each other via AstIndex, see AstNode.

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

§elements: AstVec<AstIndex>

The tuple’s elements

§parentheses: bool

Whether or not parentheses were used for the tuple

§

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

§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

A map literal, containing a series of key/value entries

Fields

§entries: AstVec<AstIndex>

The map’s entries.

If the map has braces, then values are optional and the valueless keys will point directly to an Id instead of a MapEntry.

§braces: bool

Whether or not the map was defined using braces.

§

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

§body: AstVec<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(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

§args: AstVec<AstIndex>

The arguments

§variadic: bool

A flag that indicates if the function arguments end with a variadic ... argument

§output_type: Option<AstIndex>

The optional output type of the function

§

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

§target: AstIndex

The target of the assignment

§expression: AstIndex

The expression to be assigned

§let_assignment: bool

Whether or not the assignment uses let

§

MultiAssign

A multiple-assignment expression

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

Fields

§targets: AstVec<AstIndex>

The targets of the assignment

§expression: AstIndex

The expression to be assigned

§let_assignment: bool

Whether or not the assignment uses let

§

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: AstVec<AstIndex>

The series of arms that match against the provided expression

§

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.

§condition: Option<AstIndex>

An optional condition for the match arm

e.g. match foo bar if check_condition bar then …

§expression: AstIndex

The body of the match arm

§

Switch(AstVec<AstIndex>)

A switch expression

§

SwitchArm

An arm of a Self::Switch expression

Fields

§condition: Option<AstIndex>

An optional condition for the switch arm

None implies else, and should always appear as the last arm.

§expression: AstIndex

The body of the switch arm

§

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

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

§

Type

A type hint

E.g. let x: Number = 0 ^~~ This is the beginning of the type hint

Fields

§type_index: ConstantIndex

The expected type as a string

§allow_null: bool

True if the type was specified with a ? suffix

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate 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 PartialEq for Node

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl VariantName for Node

Source§

fn variant_name(&self) -> &'static str

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.