pub enum Expr {
Show 14 variants
Literal(Literal),
Binary(Binary),
Unary(Unary),
Variable(Variable),
Parenthesized(Parenthesized),
Call(CallExpr),
Assign(Assign),
Vec(VecExpr),
Access(AccessExpr),
Spread(Spread),
Null(Token),
StructConstructor(StructConstructor),
ThenElse(ThenElse),
Object(ObjectExpr),
}Expand description
Enum representing an expression in the AST. Expressions include literals, binary operations, unary operations, and more.
Variants§
Literal(Literal)
A literal value (e.g., number, string).
Binary(Binary)
A binary operation (e.g., a + b).
Unary(Unary)
A unary operation (e.g., -a).
Variable(Variable)
A variable reference.
Parenthesized(Parenthesized)
A parenthesized expression to override precedence.
Call(CallExpr)
A function call expression.
Assign(Assign)
An assignment expression (e.g., a = b).
Vec(VecExpr)
A vector (list) of expressions.
Access(AccessExpr)
An access expression (e.g., struct.name, arr[0], Person::new).
Spread(Spread)
A spread operator for variadic arguments. (e.g., ...args)
Null(Token)
Null literal.
StructConstructor(StructConstructor)
Struct constructor. (e.g., MyStruct { field: value })
ThenElse(ThenElse)
Then-else expression. (e.g., if condition then value else other)
Object(ObjectExpr)
Object expression.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn into_variable(self) -> Variable
pub fn into_variable(self) -> Variable
Sourcepub fn new_spread(token: Token, expr: Expr) -> Expr
pub fn new_spread(token: Token, expr: Expr) -> Expr
Sourcepub fn new_then_else(
condition: Expr,
then_expr: Expr,
else_expr: Expr,
then_token: Token,
else_token: Token,
) -> Expr
pub fn new_then_else( condition: Expr, then_expr: Expr, else_expr: Expr, then_token: Token, else_token: Token, ) -> Expr
Creates a new then-else expression.
§Arguments
condition- The condition expression.then_expr- The expression to evaluate if the condition is true.else_expr- The expression to evaluate if the condition is false.then_token- The token representing thethenkeyword.else_token- The token representing theelsekeyword.
§Returns
A new Expr::ThenElse variant.
Sourcepub fn new_assign(left: Expr, op: AssignOperator, right: Expr) -> Expr
pub fn new_assign(left: Expr, op: AssignOperator, right: Expr) -> Expr
Sourcepub fn new_binary(left: Expr, operator: BinOperator, right: Expr) -> Expr
pub fn new_binary(left: Expr, operator: BinOperator, right: Expr) -> Expr
Sourcepub fn new_integer(token: Token, value: i64) -> Expr
pub fn new_integer(token: Token, value: i64) -> Expr
Sourcepub fn new_variable(ident: Token, name: String) -> Expr
pub fn new_variable(ident: Token, name: String) -> Expr
Sourcepub fn new_string(token: Token, value: String) -> Expr
pub fn new_string(token: Token, value: String) -> Expr
Sourcepub fn new_parenthesized(expr: Expr) -> Expr
pub fn new_parenthesized(expr: Expr) -> Expr
Sourcepub fn new_struct_constructor(
name: String,
fields: Vec<(String, Expr)>,
token: Token,
) -> Expr
pub fn new_struct_constructor( name: String, fields: Vec<(String, Expr)>, token: Token, ) -> Expr
Trait Implementations§
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 UnwindSafe for Expr
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)