Skip to main content

AstContext

Struct AstContext 

Source
pub struct AstContext { /* private fields */ }
Expand description

ParserContext implementation that builds a span-carrying Expr tree instead of executing. Consults no OpLookup, inspects no runtime types, and never fails on semantic grounds — resolution and type/range checking are deferred to a later, separate type-checking phase (see the module doc comment).

§Examples

use cel_parser::{AstContext, ParserContext};
use proc_macro2::Span;

let mut ctx = AstContext::new_context();
ctx.push_literal(10i32, Span::call_site());

Implementations§

Source§

impl AstContext

Source

pub fn into_expr(self) -> Expr

Consumes the context, returning the single parsed expression.

  • Precondition: parsing completed successfully (exactly one node remains).

Trait Implementations§

Source§

impl Debug for AstContext

Source§

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

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

impl Default for AstContext

Source§

fn default() -> AstContext

Returns the “default value” for a type. Read more
Source§

impl ParserContext for AstContext

Source§

fn apply_member( &mut self, _lookup: &OpLookup, name: &str, name_span: ExprSpan, explicit_args: Option<usize>, start: Span, end: Span, ) -> Result<()>

Records member spelling and source-order operands without resolving their types.

  • Complexity: O(n) in the number of explicit arguments.
Source§

fn make_record( &mut self, _lookup: &OpLookup, name: &str, name_span: ExprSpan, fields: Vec<(String, ExprSpan)>, _ambient_start: usize, start: Span, end: Span, ) -> Result<()>

Records source-order field names and values without resolving a constructor.

  • Complexity: O(f) in the number of fields.
Source§

fn resolves_closure_types() -> bool

Returns whether closure annotations must resolve while parsing rather than remain syntax. Read more
Source§

fn new_context() -> Self

Creates a fresh, empty context with no operations recorded yet.
Source§

fn new_fragment(&self) -> Self

Creates an empty fragment for building an alternate branch (one side of a short-circuiting ||/&&, or an if/else branch), independent of self. Read more
Source§

fn push_literal<T: 'static + Clone>(&mut self, value: T, span: Span)

Pushes a literal value with the source span of the token it came from.
Source§

fn apply_op( &mut self, _op_lookup: &OpLookup, name: &str, arity: usize, start: Span, end: Span, ) -> Result<()>

Applies a named operator or zero-arity identifier lookup, using op_lookup to resolve it against whatever this context currently holds. Read more
Source§

fn apply_logical( &mut self, name: &str, rhs: Self, start: Span, end: Span, ) -> Result<()>

Applies a short-circuiting logical operator ("||" or "&&"), consuming a leading condition value already present on self and folding in rhs, the already-parsed right-hand-side fragment. Read more
Source§

fn join2( &mut self, then_fragment: Self, else_fragment: Option<Self>, start: Span, end: Span, ) -> Result<()>

Joins a previously-built fragment into self, consuming a leading condition value already present on self. then_fragment’s contribution is used when the condition is true; else_fragment’s when false, or None if the source had no else/else if at all. start/end cover the whole if/else construct. Read more
Source§

fn make_tuple( &mut self, n: usize, ambient_start: usize, start: Span, end: Span, ) -> Result<()>

Combines the last n emitted values into a single tuple value. start/end cover the whole (...) construct. Read more
Source§

fn make_array( &mut self, n: usize, ambient_start: usize, start: Span, end: Span, ) -> Result<()>

Combines the last n emitted values into a single homogeneous array value. start/end cover the whole [...] construct, and ambient_start is the stack offset the first element was emitted at (as reported by Self::current_stack_offset before parsing it). Read more
Source§

fn make_annotated_array( &mut self, n: usize, ambient_start: usize, annotation: AnnotatedArray<'_>, start: Span, end: Span, ) -> Result<()>

Combines the last n emitted values into a single array value, honoring annotation’s optional type ascription. Read more
Source§

fn peek_tuple_arity(&self) -> Option<usize>

Returns the arity of the tuple currently on top, or None if the top value isn’t a tuple.
Source§

fn tuple_index(&mut self, index: usize, start: Span, end: Span) -> Result<()>

Replaces the tuple on top with its index-th element. start/end cover the base expression through the index token. Read more
Source§

fn current_stack_offset(&self) -> usize

Returns the current stack offset, used to compute tuple layouts.
Source§

fn apply_cast( &mut self, _op_lookup: &OpLookup, type_name: &str, start: Span, end: Span, ) -> Result<()>

Applies a cast (expr as Type), consuming the operand already present on self and replacing it with the converted value. type_name is the target type’s bare identifier text (e.g. "i32", "bool", "String"), unresolved by the grammar itself. Read more
Source§

fn push_closure( &mut self, param_types: Vec<ValueType>, params: Vec<ClosureParam>, body: Self, span: Span, ) -> Result<()>

Packages a fully-parsed, independent nested context — the body of a closure literal — as a value pushed onto self, given the closure’s declared parameter types in two parallel forms: param_types (each parameter’s complete runtime shape, in order) for an implementation that executes, and params (each parameter’s name, span, and unresolved type expression) for one that builds an AST instead. An implementation uses whichever it needs and ignores the other. Read more
Source§

fn output_type_id(&self) -> Option<TypeId>

Returns the TypeId of the single value self currently holds, or None if that isn’t known/applicable for this ParserContext implementation. Read more

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