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§
Trait Implementations§
Source§impl Debug for AstContext
impl Debug for AstContext
Source§impl Default for AstContext
impl Default for AstContext
Source§fn default() -> AstContext
fn default() -> AstContext
Returns the “default value” for a type. Read more
Source§impl ParserContext for AstContext
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<()>
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<()>
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
fn resolves_closure_types() -> bool
Returns whether closure annotations must resolve while parsing rather than remain syntax. Read more
Source§fn new_context() -> Self
fn new_context() -> Self
Creates a fresh, empty context with no operations recorded yet.
Source§fn new_fragment(&self) -> Self
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 moreSource§fn push_literal<T: 'static + Clone>(&mut self, value: T, span: Span)
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<()>
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 moreSource§fn apply_logical(
&mut self,
name: &str,
rhs: Self,
start: Span,
end: Span,
) -> Result<()>
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 moreSource§fn join2(
&mut self,
then_fragment: Self,
else_fragment: Option<Self>,
start: Span,
end: Span,
) -> Result<()>
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 moreSource§fn make_tuple(
&mut self,
n: usize,
ambient_start: usize,
start: Span,
end: Span,
) -> Result<()>
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 moreSource§fn make_array(
&mut self,
n: usize,
ambient_start: usize,
start: Span,
end: Span,
) -> Result<()>
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 moreSource§fn make_annotated_array(
&mut self,
n: usize,
ambient_start: usize,
annotation: AnnotatedArray<'_>,
start: Span,
end: Span,
) -> Result<()>
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 moreSource§fn peek_tuple_arity(&self) -> Option<usize>
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<()>
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 moreSource§fn current_stack_offset(&self) -> usize
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<()>
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 moreSource§fn push_closure(
&mut self,
param_types: Vec<ValueType>,
params: Vec<ClosureParam>,
body: Self,
span: Span,
) -> Result<()>
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 moreAuto Trait Implementations§
impl !Send for AstContext
impl !Sync for AstContext
impl Freeze for AstContext
impl RefUnwindSafe for AstContext
impl Unpin for AstContext
impl UnsafeUnpin for AstContext
impl UnwindSafe for AstContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more