[][src]Enum arithmetic_parser::Expr

#[non_exhaustive]pub enum Expr<'a, T: Grammar> {
    Variable,
    Literal(T::Lit),
    FnDefinition(FnDefinition<'a, T>),
    Function {
        name: Box<SpannedExpr<'a, T>>,
        args: Vec<SpannedExpr<'a, T>>,
    },
    Method {
        name: Spanned<'a>,
        receiver: Box<SpannedExpr<'a, T>>,
        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>),
}

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

Variants (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 }.

Function

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

Fields of Function

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.

Method

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

Fields of Method

name: Spanned<'a>

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

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

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

Unary

Unary operation, e.g., -x.

Fields of Unary

op: Spanned<'a, UnaryOp>

Operator.

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

Inner expression.

Binary

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

Fields of Binary

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

Implementations

impl<T: Grammar, '_> Expr<'_, T>[src]

pub fn binary_lhs(&self) -> Option<&SpannedExpr<'_, T>>[src]

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

pub fn binary_rhs(&self) -> Option<&SpannedExpr<'_, T>>[src]

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

pub fn ty(&self) -> ExprType[src]

Returns the type of this expression.

Trait Implementations

impl<T: Grammar, '_> Clone for Expr<'_, T>[src]

impl<'a, T: Debug + Grammar> Debug for Expr<'a, T> where
    T::Lit: Debug
[src]

impl<T, '_> PartialEq<Expr<'_, T>> for Expr<'_, T> where
    T: Grammar,
    T::Lit: PartialEq,
    T::Type: PartialEq
[src]

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.