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
impl AstContext
Sourcepub fn into_expr(self) -> Expr
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
impl Debug for AstContext
Source§impl Default for AstContext
impl Default for AstContext
Source§impl ParserContext for AstContext
impl ParserContext for AstContext
Source§fn resolves_closure_types() -> bool
fn resolves_closure_types() -> bool
Defers closure annotation resolution to semantic checking or compilation.
Source§fn new_context() -> Self
fn new_context() -> Self
Creates an empty syntax stack.
Source§fn new_fragment(&self) -> Self
fn new_fragment(&self) -> Self
Creates an independent empty syntax stack.
Source§fn push_literal<T: 'static + Clone>(&mut self, value: T, span: Span)
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<()>
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
arityoperands, 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<()>
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 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<()>
Records a lazy logical operation without replacing it with conditional syntax.
- Precondition:
nameis"&&"or"||"; each side contains one expression.
Source§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<()>
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<()>
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
nnodes followambient_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<()>
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
nnodes followambient_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<()>
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
nnodes followambient_start. - Complexity: O(n) time and space for n elements.
Source§fn peek_tuple_arity(&self) -> Option<usize>
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<()>
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
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<()>
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<()>
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:
bodycontains exactly one expression.