Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 13 variants Struct { name: String, name_span: ExprSpan, fields: Vec<RecordInit>, span: ExprSpan, }, Literal { value: Literal, span: ExprSpan, }, Ident { name: String, span: ExprSpan, }, Op { name: String, operands: Vec<Expr>, span: ExprSpan, }, Apply { callee: Box<Expr>, args: Vec<Expr>, span: ExprSpan, }, Member { receiver: Box<Expr>, name: String, name_span: ExprSpan, args: Option<Vec<Expr>>, span: ExprSpan, }, Tuple { elements: Vec<Expr>, span: ExprSpan, }, Array { elements: Vec<Expr>, type_annotation: Option<TypeExpr>, annotation_span: Option<ExprSpan>, span: ExprSpan, }, TupleIndex { base: Box<Expr>, index: usize, span: ExprSpan, }, If { cond: Box<Expr>, then_branch: Box<Expr>, else_branch: Option<Box<Expr>>, span: ExprSpan, }, Logical { op: LogicalOp, lhs: Box<Expr>, rhs: Box<Expr>, span: ExprSpan, }, Cast { expr: Box<Expr>, type_name: String, span: ExprSpan, }, Closure { params: Vec<ClosureParam>, body: Box<Expr>, span: ExprSpan, },
}
Expand description

A parsed CEL expression with source spans on every node.

Built by AstContext; consumed as-is by adam-lang (method bodies/initializers), the language server (hover/goto), the formatter, and the future macro-compilation backend. Carries no resolved types or operator overloads — resolution is deferred to a later, separate type-checking phase.

Logical is kept distinct from If (rather than desugaring a || b to if a { true } else { b }, which is how DynSegmentContext executes it) so a formatter can round-trip a || b as a || b.

Variants§

§

Struct

A named record constructor, unresolved until semantic checking.

§Examples

use cel_parser::{AstContext, Expr, OpLookup, Parser};
let expr = Parser::<AstContext>::new(OpLookup::new())
    .parse_str_ast("Point { x: 1.0 }").unwrap();
assert!(matches!(expr, Expr::Struct { fields, .. } if fields.len() == 1));

Fields

§name: String

The constructor’s type name, not a value reference.

§name_span: ExprSpan

The constructor name token’s span.

§fields: Vec<RecordInit>

Field labels and expressions in their written evaluation order.

§span: ExprSpan

The whole constructor, including the closing brace.

§

Literal

A literal value (10i32, "x", true, (), …).

Fields

§value: Literal

The literal’s value.

§span: ExprSpan

The literal token’s span.

§

Ident

A bare identifier reference or zero-arg builtin lookup (x, pi) — unresolved.

Fields

§name: String

The identifier’s name.

§span: ExprSpan

The identifier token’s span.

§

Op

A prefix (arity 1) or infix (arity 2) operator application (-x, a + b, a == b).

Fields

§name: String

The operator’s name (e.g. "+", "-", "==").

§operands: Vec<Expr>

The operand sub-expressions, in source order.

§span: ExprSpan

The span of the whole operator application.

§

Apply

A call: callee(args...) — the grammar’s "()" operator.

Fields

§callee: Box<Expr>

The expression being called.

§args: Vec<Expr>

The argument sub-expressions, in source order.

§span: ExprSpan

The span of the whole call, including its argument list.

§

Member

A direct receiver operation (receiver.name or receiver.name(args...)).

The label is not an identifier reference. Type and overload resolution are deferred.

§Examples

use cel_parser::{AstContext, Expr, OpLookup, Parser};
let expr = Parser::<AstContext>::new(OpLookup::new()).parse_str_ast("a.x()").unwrap();
assert!(matches!(expr, Expr::Member { args: Some(args), .. } if args.is_empty()));

Fields

§receiver: Box<Expr>

The receiver, evaluated before explicit arguments.

§name: String

The operation’s name.

§name_span: ExprSpan

The member name token’s span.

§args: Option<Vec<Expr>>

Explicit arguments in source order; None preserves property spelling.

§span: ExprSpan

The span from the receiver through the name or closing parenthesis.

§

Tuple

A tuple literal ((a, b, ...); a 1-tuple is (a,)).

Fields

§elements: Vec<Expr>

The element sub-expressions, in source order.

§span: ExprSpan

The span of the whole tuple, including its parentheses.

§

Array

An array literal ([a, b, ...], [a, b]: [T], or []: [T]). An unannotated empty array is still rejected by the grammar (see https://github.com/stlab/cel-rs/issues/212), but a typed empty array is recorded here with elements.is_empty(). type_annotation stores the complete recursive array type exactly as written, including nested arrays and custom leaf names such as Custom. Whether the elements share one type, whether type_annotation names a complete array type are deferred to the later type-checking phase (see the module doc comment), same as TupleIndex’s deferred bounds check.

Fields

§elements: Vec<Expr>

The element sub-expressions, in source order.

§type_annotation: Option<TypeExpr>

The optional declared array type, as written after :.

§annotation_span: Option<ExprSpan>

The span from the : token through the end of the declared type, when present.

§span: ExprSpan

The span of the whole array literal, including its brackets and any annotation.

§

TupleIndex

A tuple index (base.N). Whether base is actually a tuple and N is in range is unchecked here — deferred to the type-checking phase (see the module doc comment).

Fields

§base: Box<Expr>

The expression being indexed.

§index: usize

The index.

§span: ExprSpan

The span from the start of base through the index token.

§

If

An if cond { then } else { else_ } expression.

Fields

§cond: Box<Expr>

The condition.

§then_branch: Box<Expr>

The then-branch.

§else_branch: Option<Box<Expr>>

The else-branch, or None if no else/else if was written.

§span: ExprSpan

The span of the whole if/else construct.

§

Logical

A short-circuiting &&/||.

Fields

§op: LogicalOp

Which logical operator.

§lhs: Box<Expr>

The left-hand side.

§rhs: Box<Expr>

The right-hand side.

§span: ExprSpan

The span of the whole logical expression.

§

Cast

A cast (expr as Type). Whether type_name is a recognized type and whether a conversion from expr’s type exists is unchecked here — deferred to the type-checking phase (see the module doc comment), same as TupleIndex’s deferred bounds check.

Fields

§expr: Box<Expr>

The expression being converted.

§type_name: String

The target type’s name, as written (e.g. "i32") - unresolved.

§span: ExprSpan

The span of the whole expr as Type construct.

§

Closure

A closure literal (|x: i32| x + 1, or || 1i32 with no parameters).

Fields

§params: Vec<ClosureParam>

The closure’s declared parameters, in source order.

§body: Box<Expr>

The closure’s body expression.

§span: ExprSpan

The span of the whole closure literal, from its opening |/|| through body.

Implementations§

Source§

impl Expr

Source

pub fn span(&self) -> ExprSpan

Returns this node’s source span.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

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 Debug for Expr

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Send for Expr

§

impl !Sync for Expr

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

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> Same for T

Source§

type Output = T

Should always be Self
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.