pub trait ExprVisitor {
type Output;
Show 17 methods
// Provided methods
fn visit_expr(&mut self, expr: &Expr) -> Option<Self::Output> { ... }
fn visit_literal(
&mut self,
_lit: &Literal,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_var(
&mut self,
_var: Var,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_slot(
&mut self,
_slot: SlotId,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_unknown(
&mut self,
_unknown: &Unknown,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_if(
&mut self,
test_expr: &Arc<Expr>,
then_expr: &Arc<Expr>,
else_expr: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_and(
&mut self,
left: &Arc<Expr>,
right: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_or(
&mut self,
left: &Arc<Expr>,
right: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_unary_app(
&mut self,
_op: UnaryOp,
arg: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_binary_op(
&mut self,
_op: BinaryOp,
arg1: &Arc<Expr>,
arg2: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_extension_function(
&mut self,
_fn_name: &Name,
args: &Arc<Vec<Expr>>,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_get_attr(
&mut self,
expr: &Arc<Expr>,
_attr: &SmolStr,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_has_attr(
&mut self,
expr: &Arc<Expr>,
_attr: &SmolStr,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_like(
&mut self,
expr: &Arc<Expr>,
_pattern: &Pattern,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_is(
&mut self,
expr: &Arc<Expr>,
_entity_type: &EntityType,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_set(
&mut self,
elements: &Arc<Vec<Expr>>,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
fn visit_record(
&mut self,
fields: &Arc<BTreeMap<SmolStr, Expr>>,
_loc: Option<&Loc>,
) -> Option<Self::Output> { ... }
}Expand description
A visitor trait for traversing Cedar Policy Abstract Syntax Trees (ASTs).
This trait enables type-safe traversal of Cedar policy expressions in the language server. Implementers can selectively override methods to process specific expression types while inheriting default behavior for others.
§Usage
Implement this trait and override the methods for the expression types you want to process.
§Traversal Behavior
By default, the visitor will traverse the expression tree depth-first, stopping and returning the first non-None result. Implementers can override this behavior by providing custom implementations for specific visit methods.
Required Associated Types§
Provided Methods§
Sourcefn visit_expr(&mut self, expr: &Expr) -> Option<Self::Output>
fn visit_expr(&mut self, expr: &Expr) -> Option<Self::Output>
Entry point for visiting an expression.
This is typically called to begin traversal and dispatches to the
relevant visit_* functions based on the expression kind.
Sourcefn visit_literal(
&mut self,
_lit: &Literal,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_literal( &mut self, _lit: &Literal, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits a literal expression (string, number, boolean, etc.).
Sourcefn visit_var(&mut self, _var: Var, _loc: Option<&Loc>) -> Option<Self::Output>
fn visit_var(&mut self, _var: Var, _loc: Option<&Loc>) -> Option<Self::Output>
Visits a variable reference (principal, resource, action, context).
Sourcefn visit_slot(
&mut self,
_slot: SlotId,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_slot( &mut self, _slot: SlotId, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits a slot reference in a policy template.
Sourcefn visit_unknown(
&mut self,
_unknown: &Unknown,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_unknown( &mut self, _unknown: &Unknown, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits an unknown value for partial evaluation
Sourcefn visit_if(
&mut self,
test_expr: &Arc<Expr>,
then_expr: &Arc<Expr>,
else_expr: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_if( &mut self, test_expr: &Arc<Expr>, then_expr: &Arc<Expr>, else_expr: &Arc<Expr>, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits an if-then-else conditional expression.
Recursively visits the condition, then branch, and else branch.
Sourcefn visit_and(
&mut self,
left: &Arc<Expr>,
right: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_and( &mut self, left: &Arc<Expr>, right: &Arc<Expr>, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits a logical AND expression.
Recursively visits the left and right operands.
Sourcefn visit_or(
&mut self,
left: &Arc<Expr>,
right: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_or( &mut self, left: &Arc<Expr>, right: &Arc<Expr>, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits a logical OR expression.
Recursively visits the left and right operands.
Sourcefn visit_unary_app(
&mut self,
_op: UnaryOp,
arg: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_unary_app( &mut self, _op: UnaryOp, arg: &Arc<Expr>, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits a unary operation (like negation).
Recursively visits the operand.
Sourcefn visit_binary_op(
&mut self,
_op: BinaryOp,
arg1: &Arc<Expr>,
arg2: &Arc<Expr>,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_binary_op( &mut self, _op: BinaryOp, arg1: &Arc<Expr>, arg2: &Arc<Expr>, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits a binary operation (like comparison or arithmetic).
Recursively visits both operands.
Sourcefn visit_extension_function(
&mut self,
_fn_name: &Name,
args: &Arc<Vec<Expr>>,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_extension_function( &mut self, _fn_name: &Name, args: &Arc<Vec<Expr>>, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits an extension function call (like ip()).
Recursively visits each argument.
Sourcefn visit_get_attr(
&mut self,
expr: &Arc<Expr>,
_attr: &SmolStr,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_get_attr( &mut self, expr: &Arc<Expr>, _attr: &SmolStr, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits an attribute access expression (e.g., expr.attr).
Recursively visits the target expression.
Sourcefn visit_has_attr(
&mut self,
expr: &Arc<Expr>,
_attr: &SmolStr,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_has_attr( &mut self, expr: &Arc<Expr>, _attr: &SmolStr, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits an attribute existence check (e.g., expr has attr).
Recursively visits the target expression.
Sourcefn visit_like(
&mut self,
expr: &Arc<Expr>,
_pattern: &Pattern,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_like( &mut self, expr: &Arc<Expr>, _pattern: &Pattern, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits a pattern-matching expression (e.g., expr like "pat").
Recursively visits the target expression.
Sourcefn visit_is(
&mut self,
expr: &Arc<Expr>,
_entity_type: &EntityType,
_loc: Option<&Loc>,
) -> Option<Self::Output>
fn visit_is( &mut self, expr: &Arc<Expr>, _entity_type: &EntityType, _loc: Option<&Loc>, ) -> Option<Self::Output>
Visits a type-checking expression (e.g., principal is User).
Recursively visits the target expression.