pub enum Expr {
}
Expand description
Represents any kind of 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}
.
Sum(Sum)
A sum expression, such as sum n in 1..10 of n
.
Product(Product)
A product expression, such as product n in 1..10 of n
.
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 { ... }
.
For(For)
A for loop expression, as in for i in 0..10 then print(i)
.
Then(Then)
A then expression, as in then x += 1
.
Of(Of)
An of expression, as in of x
.
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.
Return(Return)
A return expression, as in return x
, used to return a value from a function.
Call(Call)
A function call, such as abs(-1)
.
Index(Index)
List indexing, such as list[0]
.
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
.
Range(Range)
A range expression, such as 1..10
.
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 an Expr::Paren
, returns the innermost expression in the
parenthesized expression. Otherwise, returns self
.
Sourcepub fn is_implicit_mul_target(&self) -> bool
pub fn is_implicit_mul_target(&self) -> bool
Returns true if the given expression can be used as a target for implicit multiplication.
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
.