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
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.
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.
Binary
Binary operation, e.g., x + 1.
Fields
lhs: Box<SpannedExpr<'a, T>>LHS of the operation.
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>
impl<'a, T: Grammar> Expr<'a, T>
sourcepub fn binary_lhs(&self) -> Option<&SpannedExpr<'a, T>>
pub fn binary_lhs(&self) -> Option<&SpannedExpr<'a, T>>
Returns LHS of the binary expression. If this is not a binary expression, returns None.
sourcepub fn binary_rhs(&self) -> Option<&SpannedExpr<'a, T>>
pub fn binary_rhs(&self) -> Option<&SpannedExpr<'a, T>>
Returns RHS of the binary expression. If this is not a binary expression, returns None.
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for Expr<'a, T>
impl<'a, T> RefUnwindSafe for Expr<'a, T>
impl<'a, T> Send for Expr<'a, T>
impl<'a, T> Sync for Expr<'a, T>
impl<'a, T> Unpin for Expr<'a, T>
impl<'a, T> UnwindSafe for Expr<'a, T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)