pub enum Atom {
}Expand description
Represents an atom expression in CalcScript.
Atom expressions are the simplest kind of expression, and are entirely unambiguous to parse, meaning that they can be parsed without needing any context.
For example, a literal value like 1 or true has no ambiguity; when we encounter a numeric
or boolean token, we know that it must be a literal value.
Some expressions, like if expressions or loop expressions, are also atom expressions,
because they have a unique keyword that identifies them; when we encounter the if keyword, we
automatically know there is only one correct way to parse the expression.
In addition, all atom expressions are self-contained. This means that atom expressions within a
larger Expr can be replaced with semantically equivalent, but different variants of atom
expressions, and the larger expression will still be valid.
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.