[][src]Enum arithmetic_parser::Expr

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

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: Span<'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.

Trait Implementations

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

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

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

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

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

impl<'a, T> UnwindSafe for Expr<'a, T> where
    <T as Grammar>::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> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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.