pub enum Expr {
Literal(Literal),
Paren(Paren),
Block(Block),
If(If),
Loop(Loop),
While(While),
Break(Break),
Continue(Continue),
Call(Call),
Unary(Unary),
Binary(Binary),
Assign(Assign),
}Expand description
Represents a general expression in CalcScript.
An expression is any valid piece of code that can be evaluated to produce a value. Expressions can be used as the right-hand side of an assignment, or as the argument to a function call.
Variants§
Literal(Literal)
A literal value.
Paren(Paren)
A parenthesized expression, such as (1 + 2).
Block(Block)
A blocked expression, such as {1 + 2}.
If(If)
An if expression, such as if x > 0 then x else -x.
Loop(Loop)
A loop expression, as in loop { ... }.
While(While)
A while loop expression, as in while x > 0 then { ... }.
Break(Break)
A break expression, used to exit a loop, optionally with a value.
Continue(Continue)
A continue expression, used to skip the rest of a loop iteration.
Call(Call)
A function call, such as abs(-1).
Unary(Unary)
A unary operation, such as -1 or !true.
Binary(Binary)
A binary operation, such as 1 + 2.
Assign(Assign)
An assignment of a variable or function, such as x = 1 or f(x) = x^2.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn post_order_iter(&self) -> ExprIter<'_> ⓘ
pub fn post_order_iter(&self) -> ExprIter<'_> ⓘ
Returns an iterator that traverses the tree of expressions in left-to-right post-order (i.e. depth-first).
Sourcepub fn innermost(&self) -> &Expr
pub fn innermost(&self) -> &Expr
If this expression is a Expr::Paren, returns the innermost expression in the
parenthesized expression. Otherwise, returns self.
Trait Implementations§
Source§impl Latex for Expr
impl Latex for Expr
Source§fn as_display(&self) -> LatexFormatter<'_, Self>
fn as_display(&self) -> LatexFormatter<'_, Self>
LatexFormatter, which implements Display.