pub enum Expr {
Show 18 variants
Assignment(AssignmentExpr),
Binary(BinaryExpr),
Unary(UnaryExpr),
Paren(ParenExpr),
Call(CallExpr),
Subset(SubsetExpr),
Subset2(Subset2Expr),
If(IfExpr),
For(ForExpr),
While(WhileExpr),
Repeat(RepeatExpr),
Function(FunctionExpr),
Block(BlockExpr),
Name(Ident),
IntLiteral(IntLit),
FloatLiteral(FloatLit),
StringLiteral(StringLit),
ComplexLiteral(ComplexLit),
}Expand description
Any R expression: a compound node (BINARY_EXPR, CALL_EXPR, …) or a leaf
atom token (a name or a literal).
Variants§
Assignment(AssignmentExpr)
Binary(BinaryExpr)
Unary(UnaryExpr)
Paren(ParenExpr)
Call(CallExpr)
Subset(SubsetExpr)
Subset2(Subset2Expr)
If(IfExpr)
For(ForExpr)
While(WhileExpr)
Repeat(RepeatExpr)
Function(FunctionExpr)
Block(BlockExpr)
Name(Ident)
A bare identifier — also covers R’s special constants (TRUE, NA, …);
call Ident::constant to distinguish.
IntLiteral(IntLit)
FloatLiteral(FloatLit)
StringLiteral(StringLit)
ComplexLiteral(ComplexLit)
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn cast(element: SyntaxElement) -> Option<Expr>
pub fn cast(element: SyntaxElement) -> Option<Expr>
Cast a CST element to an expression. A node dispatches on its kind; a
token becomes an atom variant (name or literal). Trivia, operators,
keywords, and punctuation are not expressions and yield None.
Sourcepub fn cast_node(node: SyntaxNode) -> Option<Expr>
pub fn cast_node(node: SyntaxNode) -> Option<Expr>
Cast a node to a compound expression. None for a non-expression node
(e.g. ARG_LIST, ROOT) — a leaf atom is a token, so use Expr::cast
when the element may be either.
Sourcepub fn syntax(&self) -> SyntaxElement
pub fn syntax(&self) -> SyntaxElement
The underlying CST element (a node for compound expressions, a token for atoms).
Sourcepub fn text_range(&self) -> TextRange
pub fn text_range(&self) -> TextRange
The source range of the expression.
Sourcepub fn is_atom(&self) -> bool
pub fn is_atom(&self) -> bool
Whether this is a primary/atomic expression — one that can be prefixed
with ! (or dropped) without reparenthesizing. Namely a name, a literal,
a call, a parenthesized expression, or an index ([/[[). This is the
guard a negating rewrite (x == FALSE → !x) needs to stay correct.