Enum Expr

Source
pub enum Expr {
Show 20 variants Literal(Literal), Paren(Paren), Block(Block), Sum(Sum), Product(Product), If(If), Loop(Loop), While(While), For(For), Then(Then), Of(Of), Break(Break), Continue(Continue), Return(Return), Call(Call), Index(Index), Unary(Unary), Binary(Binary), Assign(Assign), Range(Range),
}
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

Source

pub fn span(&self) -> Range<usize>

Returns the span of the expression.

Source

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).

Source

pub fn innermost(&self) -> &Expr

If this expression is an Expr::Paren, returns the innermost expression in the parenthesized expression. Otherwise, returns self.

Source

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 Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Atom> for Expr

Source§

fn from(atom: Atom) -> Self

Converts to this type from the input type.
Source§

impl From<Primary> for Expr

Source§

fn from(primary: Primary) -> Self

Converts to this type from the input type.
Source§

impl Latex for Expr

Source§

fn fmt_latex(&self, f: &mut Formatter<'_>) -> Result

Format the value as LaTeX.
Source§

fn as_display(&self) -> LatexFormatter<'_, Self>

Wraps the value in a LatexFormatter, which implements Display.
Source§

impl<'source> Parse<'source> for Expr

Source§

fn std_parse( input: &mut Parser<'source>, recoverable_errors: &mut Vec<Error>, ) -> Result<Self, Vec<Error>>

Parses a value from the given stream of tokens, advancing the stream past the consumed tokens if parsing is successful. Read more
Source§

fn parse(input: &mut Parser<'source>) -> ParseResult<Self>

Parses a value from the given stream of tokens, advancing the stream past the consumed tokens if parsing is successful. Read more
Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Expr

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Fmt for T
where T: Display,

Source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
Source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.