Enum Atom

Source
pub enum Atom {
Show 14 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),
}
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.

Trait Implementations§

Source§

impl Clone for Atom

Source§

fn clone(&self) -> Atom

Returns a duplicate 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 Atom

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<Atom> for Primary

Source§

fn from(atom: Atom) -> Self

Converts to this type from the input type.
Source§

impl<'source> Parse<'source> for Atom

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 Atom

Source§

fn eq(&self, other: &Atom) -> 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 Atom

Source§

impl StructuralPartialEq for Atom

Auto Trait Implementations§

§

impl Freeze for Atom

§

impl RefUnwindSafe for Atom

§

impl Send for Atom

§

impl Sync for Atom

§

impl Unpin for Atom

§

impl UnwindSafe for Atom

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