Skip to main content

Expression

Enum Expression 

Source
pub enum Expression<'s> {
Show 25 variants Literal(TokenRef<'s>), InterpolatedString(&'s Token<'s>, Vec<Expression<'s>>), Variable(TokenRef<'s>), Grouping(TokenRef<'s>, Box<Expression<'s>>, TokenRef<'s>), Record(TokenRef<'s>, Vec<RecordElement<'s>>, TokenRef<'s>), Array(TokenRef<'s>, Vec<ArrayElement<'s>>, TokenRef<'s>), Call(Callable<'s>, TokenRef<'s>, Vec<ArgElement<'s>>, TokenRef<'s>), TaggedString(Box<Expression<'s>>, Box<Expression<'s>>), Extension(Box<Expression<'s>>, TokenRef<'s>, Callable<'s>, TokenRef<'s>, Vec<ArgElement<'s>>, TokenRef<'s>), Access(Box<Expression<'s>>, TokenRef<'s>, TokenRef<'s>), Index(Box<Expression<'s>>, TokenRef<'s>, Box<Expression<'s>>, TokenRef<'s>), Slice(Box<Expression<'s>>, TokenRef<'s>, Option<Box<Expression<'s>>>, TokenRef<'s>, Option<Box<Expression<'s>>>, TokenRef<'s>), NonNil(Box<Expression<'s>>, TokenRef<'s>), Prefix(TokenRef<'s>, Box<Expression<'s>>), Infix(Box<Expression<'s>>, TokenRef<'s>, Box<Expression<'s>>), Is(Box<Expression<'s>>, TokenRef<'s>, Box<Pattern<'s>>), Block(TokenRef<'s>, Vec<Statement<'s>>, Option<Box<Expression<'s>>>, TokenRef<'s>), Loop(TokenRef<'s>, Box<Expression<'s>>), While(TokenRef<'s>, Box<Expression<'s>>, Box<Expression<'s>>, Option<ElseBlock<'s>>), ForIn(TokenRef<'s>, Box<Pattern<'s>>, TokenRef<'s>, Box<Iterable<'s>>, Box<Expression<'s>>, Option<ElseBlock<'s>>), If(TokenRef<'s>, Box<Expression<'s>>, Box<Expression<'s>>, Option<ElseBlock<'s>>), Cond(Box<Expression<'s>>, TokenRef<'s>, Box<Expression<'s>>, TokenRef<'s>, Box<Expression<'s>>), Match(TokenRef<'s>, Box<Expression<'s>>, TokenRef<'s>, Vec<MatchCase<'s>>, TokenRef<'s>), Function(TokenRef<'s>, Option<ParameterList<'s>>, Box<Expression<'s>>), Unknown { recovered: Option<Box<Expression<'s>>>, tokens: Vec<TokenRef<'s>>, errors: Vec<SourceDiagnostic>, },
}

Variants§

§

Literal(TokenRef<'s>)

number | string | ordinal | true | false | nil

§

InterpolatedString(&'s Token<'s>, Vec<Expression<'s>>)

interpolated_string

Holds a crate::lexer::TokenKind::InterpolatedString, and a list of expressions that are interpolated into the string.

§

Variable(TokenRef<'s>)

identifier

§

Grouping(TokenRef<'s>, Box<Expression<'s>>, TokenRef<'s>)

( expression )

§

Record(TokenRef<'s>, Vec<RecordElement<'s>>, TokenRef<'s>)

( element* )

Use () for an empty record.

For a single-element-unnamed record, use ( expression , ).

For convenience for JSON-like data, allows following JSON-style trailing record:

{ ( ( string | interpolated_string ) : expression , )+ }

§

Array(TokenRef<'s>, Vec<ArrayElement<'s>>, TokenRef<'s>)

[ element* ]

Use [] for an empty list.

§

Call(Callable<'s>, TokenRef<'s>, Vec<ArgElement<'s>>, TokenRef<'s>)

callable ( arguments )

Arguments are a list of expressions, trailing comma is optional.

§

TaggedString(Box<Expression<'s>>, Box<Expression<'s>>)

expression ( interpolated_string | string )

§

Extension(Box<Expression<'s>>, TokenRef<'s>, Callable<'s>, TokenRef<'s>, Vec<ArgElement<'s>>, TokenRef<'s>)

expression :: extension ( arguments ) extension : identifier (. ( identifier | ordinal ))* | pseudo_function | ( expression ) ;

Like Call, but expression is used as the first argument.

§

Access(Box<Expression<'s>>, TokenRef<'s>, TokenRef<'s>)

expression . field

Field must be an identifier or an ordinal.

§

Index(Box<Expression<'s>>, TokenRef<'s>, Box<Expression<'s>>, TokenRef<'s>)

expression [ expression ]

§

Slice(Box<Expression<'s>>, TokenRef<'s>, Option<Box<Expression<'s>>>, TokenRef<'s>, Option<Box<Expression<'s>>>, TokenRef<'s>)

expression [ additive_expression? (.. | ..<) additive_expression? ]

§

NonNil(Box<Expression<'s>>, TokenRef<'s>)

expression !

§

Prefix(TokenRef<'s>, Box<Expression<'s>>)

op expression

Prefix operators are:

  • ! logical not
  • - negation
  • + unary plus
§

Infix(Box<Expression<'s>>, TokenRef<'s>, Box<Expression<'s>>)

expression op expression

Infix operators are:

  1. ^ exponentiation
  2. * / % multiplicative
  3. + - additive
  4. is matching *Use Expression::Is for this
  5. > < >= <= in relational
  6. == != =~ !~ equality
  7. && logical and
  8. || logical or
§

Is(Box<Expression<'s>>, TokenRef<'s>, Box<Pattern<'s>>)

expression is pattern

§

Block(TokenRef<'s>, Vec<Statement<'s>>, Option<Box<Expression<'s>>>, TokenRef<'s>)

{ statements* expression? }

The value of the block is the value of the last expression. If no expression is present, the value is nil.

§

Loop(TokenRef<'s>, Box<Expression<'s>>)

loop block_expression

The final expression of the block must not present.

The value of the block is the expression of the break statement if present. Otherwise, nil.

§

While(TokenRef<'s>, Box<Expression<'s>>, Box<Expression<'s>>, Option<ElseBlock<'s>>)

while expression block_expression (else expression)?

The final expression of the block must not present.

The else_block is a block expression or an if expression.

The value of the block is the expression of the break statement if present. Otherwise, if the else_block is present, the value is the value of the else_block. Otherwise, nil.

§

ForIn(TokenRef<'s>, Box<Pattern<'s>>, TokenRef<'s>, Box<Iterable<'s>>, Box<Expression<'s>>, Option<ElseBlock<'s>>)

for pattern in expression block_expression (else expression)?

The final expression of the block must not present.

The else_block is a block expression or an if expression.

The value of the block is the expression of the break statement if present. Otherwise, if the else_block is present, the value is the value of the else_block. Otherwise, nil.

§

If(TokenRef<'s>, Box<Expression<'s>>, Box<Expression<'s>>, Option<ElseBlock<'s>>)

if expression block_expression (else expression)?

The then_block is a block expression.

The else_block is a block expression or an if expression.

§

Cond(Box<Expression<'s>>, TokenRef<'s>, Box<Expression<'s>>, TokenRef<'s>, Box<Expression<'s>>)

cond ? expression : expression

§

Match(TokenRef<'s>, Box<Expression<'s>>, TokenRef<'s>, Vec<MatchCase<'s>>, TokenRef<'s>)

match expression { ( case pattern (if expression)? block_expression )* }

The value of the block is the value of the matched expression.

If no match is found, the value is nil.

§

Function(TokenRef<'s>, Option<ParameterList<'s>>, Box<Expression<'s>>)

fn parameters? block_expression

Just like function declarations, but without the identifier. See Statement::Function for more details.

§

Unknown

Unknown expression

Fields

§recovered: Option<Box<Expression<'s>>>
§tokens: Vec<TokenRef<'s>>

Implementations§

Source§

impl<'s> Expression<'s>

Source

pub const fn is_literal(&self) -> bool

Returns true if the enum is Expression::Literal otherwise false

Source

pub const fn is_interpolated_string(&self) -> bool

Returns true if the enum is Expression::InterpolatedString otherwise false

Source

pub const fn is_variable(&self) -> bool

Returns true if the enum is Expression::Variable otherwise false

Source

pub const fn is_grouping(&self) -> bool

Returns true if the enum is Expression::Grouping otherwise false

Source

pub const fn is_record(&self) -> bool

Returns true if the enum is Expression::Record otherwise false

Source

pub const fn is_array(&self) -> bool

Returns true if the enum is Expression::Array otherwise false

Source

pub const fn is_call(&self) -> bool

Returns true if the enum is Expression::Call otherwise false

Source

pub const fn is_tagged_string(&self) -> bool

Returns true if the enum is Expression::TaggedString otherwise false

Source

pub const fn is_extension(&self) -> bool

Returns true if the enum is Expression::Extension otherwise false

Source

pub const fn is_access(&self) -> bool

Returns true if the enum is Expression::Access otherwise false

Source

pub const fn is_index(&self) -> bool

Returns true if the enum is Expression::Index otherwise false

Source

pub const fn is_slice(&self) -> bool

Returns true if the enum is Expression::Slice otherwise false

Source

pub const fn is_non_nil(&self) -> bool

Returns true if the enum is Expression::NonNil otherwise false

Source

pub const fn is_prefix(&self) -> bool

Returns true if the enum is Expression::Prefix otherwise false

Source

pub const fn is_infix(&self) -> bool

Returns true if the enum is Expression::Infix otherwise false

Source

pub const fn is_is(&self) -> bool

Returns true if the enum is Expression::Is otherwise false

Source

pub const fn is_block(&self) -> bool

Returns true if the enum is Expression::Block otherwise false

Source

pub const fn is_loop(&self) -> bool

Returns true if the enum is Expression::Loop otherwise false

Source

pub const fn is_while(&self) -> bool

Returns true if the enum is Expression::While otherwise false

Source

pub const fn is_for_in(&self) -> bool

Returns true if the enum is Expression::ForIn otherwise false

Source

pub const fn is_if(&self) -> bool

Returns true if the enum is Expression::If otherwise false

Source

pub const fn is_cond(&self) -> bool

Returns true if the enum is Expression::Cond otherwise false

Source

pub const fn is_match(&self) -> bool

Returns true if the enum is Expression::Match otherwise false

Source

pub const fn is_function(&self) -> bool

Returns true if the enum is Expression::Function otherwise false

Source

pub const fn is_unknown(&self) -> bool

Returns true if the enum is Expression::Unknown otherwise false

Trait Implementations§

Source§

impl<'s> Clone for Expression<'s>

Source§

fn clone(&self) -> Expression<'s>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'s> Debug for Expression<'s>

Source§

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

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

impl<'s> PartialEq for Expression<'s>

Source§

fn eq(&self, other: &Expression<'s>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<'s> StructuralPartialEq for Expression<'s>

Auto Trait Implementations§

§

impl<'s> Freeze for Expression<'s>

§

impl<'s> RefUnwindSafe for Expression<'s>

§

impl<'s> Send for Expression<'s>

§

impl<'s> Sync for Expression<'s>

§

impl<'s> Unpin for Expression<'s>

§

impl<'s> UnsafeUnpin for Expression<'s>

§

impl<'s> UnwindSafe for Expression<'s>

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.