Enum arithmetic_parser::Expr

source ·
#[non_exhaustive]
pub enum Expr<'a, T: Grammar> { Variable, Literal(T::Lit), FnDefinition(FnDefinition<'a, T>), TypeCast { value: Box<SpannedExpr<'a, T>>, ty: Spanned<'a, T::Type<'a>>, }, Function { name: Box<SpannedExpr<'a, T>>, args: Vec<SpannedExpr<'a, T>>, }, FieldAccess { name: Box<SpannedExpr<'a, T>>, receiver: Box<SpannedExpr<'a, T>>, }, Method { name: Box<SpannedExpr<'a, T>>, receiver: Box<SpannedExpr<'a, T>>, separator: Spanned<'a>, args: Vec<SpannedExpr<'a, T>>, }, Unary { op: Spanned<'a, UnaryOp>, inner: Box<SpannedExpr<'a, T>>, }, Binary { lhs: Box<SpannedExpr<'a, T>>, op: Spanned<'a, BinaryOp>, rhs: Box<SpannedExpr<'a, T>>, }, Tuple(Vec<SpannedExpr<'a, T>>), Block(Block<'a, T>), Object(ObjectExpr<'a, T>), }
Expand description

Arithmetic expression with an abstract types for type annotations and literals.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Variable

Variable use, e.g., x.

§

Literal(T::Lit)

Literal (semantic depends on T).

§

FnDefinition(FnDefinition<'a, T>)

Function definition, e.g., |x, y| { x + y }.

§

TypeCast

Type cast, e.g., x as Bool.

Fields

§value: Box<SpannedExpr<'a, T>>

Value being cast, e.g., x in x as Bool.

§ty: Spanned<'a, T::Type<'a>>

Type annotation for the case, e.g., Bool in x as Bool.

§

Function

Function call, e.g., foo(x, y) or |x| { x + 5 }(3).

Fields

§name: Box<SpannedExpr<'a, T>>

Function value. In the simplest case, this is a variable, but may also be another kind of expression, such as |x| { x + 5 } in |x| { x + 5 }(3).

§args: Vec<SpannedExpr<'a, T>>

Function arguments.

§

FieldAccess

Field access, e.g., foo.bar.

Fields

§name: Box<SpannedExpr<'a, T>>

Name of the called method, e.g. bar in foo.bar.

§receiver: Box<SpannedExpr<'a, T>>

Receiver of the call, e.g., foo in foo.bar(x, 5).

§

Method

Method call, e.g., foo.bar(x, 5).

Fields

§name: Box<SpannedExpr<'a, T>>

Name of the called method, e.g. bar in foo.bar(x, 5).

§receiver: Box<SpannedExpr<'a, T>>

Receiver of the call, e.g., foo in foo.bar(x, 5).

§separator: Spanned<'a>

Separator between the receiver and the called method, e.g., . in foo.bar(x, 5).

§args: Vec<SpannedExpr<'a, T>>

Arguments; e.g., x, 5 in foo.bar(x, 5).

§

Unary

Unary operation, e.g., -x.

Fields

§op: Spanned<'a, UnaryOp>

Operator.

§inner: Box<SpannedExpr<'a, T>>

Inner expression.

§

Binary

Binary operation, e.g., x + 1.

Fields

§lhs: Box<SpannedExpr<'a, T>>

LHS of the operation.

§op: Spanned<'a, BinaryOp>

Operator.

§rhs: Box<SpannedExpr<'a, T>>

RHS of the operation.

§

Tuple(Vec<SpannedExpr<'a, T>>)

Tuple expression, e.g., (x, y + z).

§

Block(Block<'a, T>)

Block expression, e.g., { x = 3; x + y }.

§

Object(ObjectExpr<'a, T>)

Object expression, e.g., #{ x, y: x + 2 }.

Implementations§

source§

impl<'a, T: Grammar> Expr<'a, T>

source

pub fn binary_lhs(&self) -> Option<&SpannedExpr<'a, T>>

Returns LHS of the binary expression. If this is not a binary expression, returns None.

source

pub fn binary_rhs(&self) -> Option<&SpannedExpr<'a, T>>

Returns RHS of the binary expression. If this is not a binary expression, returns None.

source

pub fn ty(&self) -> ExprType

Returns the type of this expression.

Trait Implementations§

source§

impl<'a, T: Grammar> Clone for Expr<'a, T>

source§

fn clone(&self) -> Self

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<'a, T: Debug + Grammar> Debug for Expr<'a, T>
where T::Lit: Debug, T::Type<'a>: Debug,

source§

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

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

impl<'a, T> PartialEq for Expr<'a, T>
where T: Grammar, T::Lit: PartialEq, T::Type<'a>: PartialEq,

source§

fn eq(&self, other: &Self) -> 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.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Expr<'a, T>
where <T as ParseLiteral>::Lit: Freeze, <T as Grammar>::Type<'a>: Freeze,

§

impl<'a, T> RefUnwindSafe for Expr<'a, T>
where <T as ParseLiteral>::Lit: RefUnwindSafe, <T as Grammar>::Type<'a>: RefUnwindSafe,

§

impl<'a, T> Send for Expr<'a, T>
where <T as ParseLiteral>::Lit: Send, <T as Grammar>::Type<'a>: Send,

§

impl<'a, T> Sync for Expr<'a, T>
where <T as ParseLiteral>::Lit: Sync, <T as Grammar>::Type<'a>: Sync,

§

impl<'a, T> Unpin for Expr<'a, T>
where <T as ParseLiteral>::Lit: Unpin, <T as Grammar>::Type<'a>: Unpin,

§

impl<'a, T> UnwindSafe for Expr<'a, T>
where <T as ParseLiteral>::Lit: UnwindSafe, <T as Grammar>::Type<'a>: UnwindSafe,

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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