Enum Primary

Source
pub enum Primary {
Show 16 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),
}
Expand description

Represents a primary expression in CalcScript.

Primary expressions extend the concept of Atom by allowing for more complex and ambiguous expressions that are still self-contained. These extensions include function calls and list indexing expressions, which can be ambiguous when encountered in isolation.

For example, when trying to parse a Primary, a literal value like abc cannot automatically be declared a Primary::Literal. Instead, we must parse forward a little more to see if this is actually calling a function named abc, or indexing into a list named abc, or neither.

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

Implementations§

Source§

impl Primary

Source

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

Returns the span of the primary expression.

Trait Implementations§

Source§

impl Clone for Primary

Source§

fn clone(&self) -> Primary

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 Primary

Source§

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

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

impl From<Atom> for Primary

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<'source> Parse<'source> for Primary

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 Primary

Source§

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

Source§

impl StructuralPartialEq for Primary

Auto Trait Implementations§

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.