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).
§Examples
use cel_parser::{AstContext, ParserContext, Expr, Literal};
let mut context = AstContext::new_context();
context.push_literal(7i32, proc_macro2::Span::call_site());
assert!(matches!(context.into_expr(), Expr::Literal { value: Literal::I32(7), .. }));

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() -> Self

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

impl ParserContext for AstContext

Source§

fn resolves_closure_types() -> bool

Defers closure annotation resolution to semantic checking or compilation.

Source§

fn new_context() -> Self

Creates an empty syntax stack.

Source§

fn new_fragment(&self) -> Self

Creates an independent empty syntax stack.

Source§

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

Transfers one supported literal into a leaf node without copying owned buffers.

Source§

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

Records an identifier, ordinary call, or operator with source-order operands.

  • Precondition: the stack contains arity operands, including a callee for "()".
  • Complexity: O(a + b) time and space for a operands and b name bytes.
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 apply_logical( &mut self, name: &str, rhs: Self, start: Span, end: Span, ) -> Result<()>

Records a lazy logical operation without replacing it with conditional syntax.

  • Precondition: name is "&&" or "||"; each side contains one expression.
Source§

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

Records one conditional, preserving an absent else rather than synthesizing syntax.

  • Precondition: the condition and each supplied branch contain one expression.
Source§

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

Collects source-order elements into a tuple, representing the empty tuple as unit.

  • Precondition: exactly n nodes follow ambient_start.
  • Complexity: O(n) time and space for n elements.
Source§

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

Collects source-order elements into an unannotated array node.

  • Precondition: exactly n nodes follow ambient_start.
  • Complexity: O(n) time and space for n elements.
Source§

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

Collects elements and retains unresolved annotation syntax and its source boundary.

  • Precondition: exactly n nodes follow ambient_start.
  • Complexity: O(n) time and space for n elements.
Source§

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

Reports no semantic tuple arity during syntax-only parsing.

Source§

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

Records every representable tuple index without prematurely checking its base type.

  • Precondition: one base expression is present.
Source§

fn current_stack_offset(&self) -> usize

Returns the node offset used to delimit the current element list.

Source§

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

Records a cast without resolving its target type.

  • Precondition: one operand is present.
  • Complexity: O(b) time and space for b type-name bytes.
Source§

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

Transfers parameter syntax and its sole body expression into a closure node.

  • Precondition: body contains exactly one expression.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.