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:
^exponentiation*/%multiplicative+-additiveismatching *Use Expression::Is for this><>=<=inrelational==!==~!~equality&&logical and||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
Implementations§
Source§impl<'s> Expression<'s>
impl<'s> Expression<'s>
Sourcepub const fn is_literal(&self) -> bool
pub const fn is_literal(&self) -> bool
Returns true if the enum is Expression::Literal otherwise false
Sourcepub const fn is_interpolated_string(&self) -> bool
pub const fn is_interpolated_string(&self) -> bool
Returns true if the enum is Expression::InterpolatedString otherwise false
Sourcepub const fn is_variable(&self) -> bool
pub const fn is_variable(&self) -> bool
Returns true if the enum is Expression::Variable otherwise false
Sourcepub const fn is_grouping(&self) -> bool
pub const fn is_grouping(&self) -> bool
Returns true if the enum is Expression::Grouping otherwise false
Sourcepub const fn is_record(&self) -> bool
pub const fn is_record(&self) -> bool
Returns true if the enum is Expression::Record otherwise false
Sourcepub const fn is_array(&self) -> bool
pub const fn is_array(&self) -> bool
Returns true if the enum is Expression::Array otherwise false
Sourcepub const fn is_call(&self) -> bool
pub const fn is_call(&self) -> bool
Returns true if the enum is Expression::Call otherwise false
Sourcepub const fn is_tagged_string(&self) -> bool
pub const fn is_tagged_string(&self) -> bool
Returns true if the enum is Expression::TaggedString otherwise false
Sourcepub const fn is_extension(&self) -> bool
pub const fn is_extension(&self) -> bool
Returns true if the enum is Expression::Extension otherwise false
Sourcepub const fn is_access(&self) -> bool
pub const fn is_access(&self) -> bool
Returns true if the enum is Expression::Access otherwise false
Sourcepub const fn is_index(&self) -> bool
pub const fn is_index(&self) -> bool
Returns true if the enum is Expression::Index otherwise false
Sourcepub const fn is_slice(&self) -> bool
pub const fn is_slice(&self) -> bool
Returns true if the enum is Expression::Slice otherwise false
Sourcepub const fn is_non_nil(&self) -> bool
pub const fn is_non_nil(&self) -> bool
Returns true if the enum is Expression::NonNil otherwise false
Sourcepub const fn is_prefix(&self) -> bool
pub const fn is_prefix(&self) -> bool
Returns true if the enum is Expression::Prefix otherwise false
Sourcepub const fn is_infix(&self) -> bool
pub const fn is_infix(&self) -> bool
Returns true if the enum is Expression::Infix otherwise false
Sourcepub const fn is_block(&self) -> bool
pub const fn is_block(&self) -> bool
Returns true if the enum is Expression::Block otherwise false
Sourcepub const fn is_loop(&self) -> bool
pub const fn is_loop(&self) -> bool
Returns true if the enum is Expression::Loop otherwise false
Sourcepub const fn is_while(&self) -> bool
pub const fn is_while(&self) -> bool
Returns true if the enum is Expression::While otherwise false
Sourcepub const fn is_for_in(&self) -> bool
pub const fn is_for_in(&self) -> bool
Returns true if the enum is Expression::ForIn otherwise false
Sourcepub const fn is_cond(&self) -> bool
pub const fn is_cond(&self) -> bool
Returns true if the enum is Expression::Cond otherwise false
Sourcepub const fn is_match(&self) -> bool
pub const fn is_match(&self) -> bool
Returns true if the enum is Expression::Match otherwise false
Sourcepub const fn is_function(&self) -> bool
pub const fn is_function(&self) -> bool
Returns true if the enum is Expression::Function otherwise false
Sourcepub const fn is_unknown(&self) -> bool
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>
impl<'s> Clone for Expression<'s>
Source§fn clone(&self) -> Expression<'s>
fn clone(&self) -> Expression<'s>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more