Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 27 variants Ident(Identifier), Path(NamePath), StringLiteral(StringLiteral), Bool { value: bool, span: Span, }, Binary { left: Box<Expr>, op: ValkyrieTokenType, right: Box<Expr>, span: Span, }, Unary { op: ValkyrieTokenType, expr: Box<Expr>, span: Span, }, Call { callee: Box<Expr>, args: Vec<Expr>, span: Span, }, Field { receiver: Box<Expr>, field: Identifier, span: Span, }, Index { receiver: Box<Expr>, index: Box<Expr>, span: Span, }, Offset { receiver: Box<Expr>, offset: Box<Expr>, span: Span, }, Paren { expr: Box<Expr>, span: Span, }, Block(Block), Lambda(LambdaExpr), Object { callee: Box<Expr>, fields: Vec<(Identifier, Option<Expr>)>, span: Span, }, AnonymousClass { parents: Vec<String>, items: Vec<Item>, captures: Vec<Identifier>, span: Span, }, If { pattern: Option<Pattern>, condition: Box<Expr>, then_branch: Block, else_branch: Option<Block>, span: Span, }, Match { scrutinee: Box<Expr>, arms: Vec<MatchArm>, span: Span, }, Loop { kind: LoopKind, label: Option<String>, pattern: Option<Pattern>, condition: Option<Box<Expr>>, body: Block, span: Span, }, Return { expr: Option<Box<Expr>>, span: Span, }, Break { label: Option<String>, expr: Option<Box<Expr>>, span: Span, }, Continue { label: Option<String>, span: Span, }, Yield { expr: Option<Box<Expr>>, yield_from: bool, span: Span, }, Raise { expr: Box<Expr>, span: Span, }, Resume { expr: Box<Expr>, span: Span, }, Catch { expr: Box<Expr>, arms: Vec<MatchArm>, span: Span, }, With { base: Box<Expr>, updates: Vec<(Identifier, Expr)>, span: Span, }, SuperCall { parent_alias: Option<Identifier>, method: Identifier, args: Vec<Expr>, span: Span, },
}
Expand description

An expression

Variants§

§

Ident(Identifier)

An identifier expression.

§

Path(NamePath)

A name path expression (e.g., std::collections::HashMap).

§

StringLiteral(StringLiteral)

A string literal expression.

§

Bool

A boolean literal expression.

Fields

§value: bool

The boolean value.

§span: Span

The source code span.

§

Binary

A binary operation expression.

Fields

§left: Box<Expr>

The left operand.

§op: ValkyrieTokenType

The binary operator.

§right: Box<Expr>

The right operand.

§span: Span

The source code span.

§

Unary

A unary operation expression.

Fields

§op: ValkyrieTokenType

The unary operator.

§expr: Box<Expr>

The operand expression.

§span: Span

The source code span.

§

Call

A function call expression.

Fields

§callee: Box<Expr>

The callee expression.

§args: Vec<Expr>

The call arguments.

§span: Span

The source code span.

§

Field

A field access expression.

Fields

§receiver: Box<Expr>

The receiver expression.

§field: Identifier

The field name.

§span: Span

The source code span.

§

Index

An index expression.

Fields

§receiver: Box<Expr>

The receiver expression.

§index: Box<Expr>

The index expression.

§span: Span

The source code span.

§

Offset

An offset expression (pointer arithmetic).

Fields

§receiver: Box<Expr>

The receiver expression.

§offset: Box<Expr>

The offset expression.

§span: Span

The source code span.

§

Paren

A parenthesized expression.

Fields

§expr: Box<Expr>

The inner expression.

§span: Span

The source code span.

§

Block(Block)

A block expression.

§

Lambda(LambdaExpr)

A lambda expression.

§

Object

An object expression.

Creates a new object instance with specified field values.

let p = Point { x: 10, y: 20 }
let shorthand = Point { x, y }  // shorthand syntax

Fields

§callee: Box<Expr>

The callee expression.

§fields: Vec<(Identifier, Option<Expr>)>

The field-value pairs. None for shorthand syntax.

§span: Span

The source code span.

§

AnonymousClass

Anonymous class expression.

let obj = class { x: 10, y: 20 }
let impl_trait = class: Trait { ... }

Fields

§parents: Vec<String>

Parent traits or classes to implement/extend.

§items: Vec<Item>

Fields and methods defined in the anonymous class.

§captures: Vec<Identifier>

Variables captured from the enclosing scope.

§span: Span

Source span.

§

If

An if expression.

Fields

§pattern: Option<Pattern>

Optional pattern for pattern-matching the condition.

§condition: Box<Expr>

The condition expression.

§then_branch: Block

The then branch block.

§else_branch: Option<Block>

The optional else branch block.

§span: Span

The source code span.

§

Match

A match expression.

Fields

§scrutinee: Box<Expr>

The expression being matched.

§arms: Vec<MatchArm>

The match arms.

§span: Span

The source code span.

§

Loop

A loop expression.

Fields

§kind: LoopKind

The loop keyword kind.

§label: Option<String>

Optional label for the loop.

§pattern: Option<Pattern>

Optional pattern for loop variable binding.

§condition: Option<Box<Expr>>

Optional condition for conditional loops.

§body: Block

The loop body.

§span: Span

The source code span.

§

Return

A return expression.

Fields

§expr: Option<Box<Expr>>

The optional return value expression.

§span: Span

The source code span.

§

Break

A break expression.

Fields

§label: Option<String>

Optional label of the loop to break from.

§expr: Option<Box<Expr>>

Optional value to break with.

§span: Span

The source code span.

§

Continue

A continue expression.

Fields

§label: Option<String>

Optional label of the loop to continue.

§span: Span

The source code span.

§

Yield

A yield expression.

Fields

§expr: Option<Box<Expr>>

The optional value to yield.

§yield_from: bool

Whether this is a yield from expression.

§span: Span

The source code span.

§

Raise

A raise (throw) expression.

Fields

§expr: Box<Expr>

The expression to raise.

§span: Span

The source code span.

§

Resume

A resume expression.

Resumes execution from an effect handler with a value. Only valid inside a catch block.

catch process() {
    case Read { prompt }: resume "input data"
}

Fields

§expr: Box<Expr>

The value to resume with.

§span: Span

The source code span.

§

Catch

A catch (try-catch) expression.

Fields

§expr: Box<Expr>

The expression to try.

§arms: Vec<MatchArm>

The catch arms.

§span: Span

The source code span.

§

With

With expression for functional record updates.

Creates a new record by copying an existing one and updating specified fields.

let p2 = p1.with { x: 20.0, y: 30.0 }
let updated = config.with { timeout: 60 }

Fields

§base: Box<Expr>

The base expression to copy from.

§updates: Vec<(Identifier, Expr)>

Field updates to apply.

§span: Span

Source span.

§

SuperCall

Super call expression for constructor chaining.

Represents a call to a parent class constructor within a subclass constructor.

class Derived(Base) {
    initiate(mut self, x: i32, y: i32) {
        super.initiate(x)  // Call parent constructor
        self.y = y
    }
}

Fields

§parent_alias: Option<Identifier>

Optional parent alias for renamed inheritance.

In renamed inheritance, specifies which parent to call:

class Child(primary: ParentA, secondary: ParentB) {
    initiate(mut self) {
        super.primary.initiate()  // alias: "primary"
    }
}
§method: Identifier

The method name to call (usually “initiate”).

§args: Vec<Expr>

Arguments passed to the parent constructor.

§span: Span

Source span.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

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

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

impl<'de> Deserialize<'de> for Expr

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Expr

Source§

impl Hash for Expr

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Expr

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for Expr

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V