ExprVisitor

Trait ExprVisitor 

Source
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§

Source

type Output

The output type for this visitor.

By default, one a visit_* function returns Some, this visitor will return that value from visit_expr.

Provided Methods§

Source

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.

Source

fn visit_literal( &mut self, _lit: &Literal, _loc: Option<&Loc>, ) -> Option<Self::Output>

Visits a literal expression (string, number, boolean, etc.).

Source

fn visit_var(&mut self, _var: Var, _loc: Option<&Loc>) -> Option<Self::Output>

Visits a variable reference (principal, resource, action, context).

Source

fn visit_slot( &mut self, _slot: SlotId, _loc: Option<&Loc>, ) -> Option<Self::Output>

Visits a slot reference in a policy template.

Source

fn visit_unknown( &mut self, _unknown: &Unknown, _loc: Option<&Loc>, ) -> Option<Self::Output>

Visits an unknown value for partial evaluation

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn visit_set( &mut self, elements: &Arc<Vec<Expr>>, _loc: Option<&Loc>, ) -> Option<Self::Output>

Visits a set literal expression (e.g., [1, 2, 3]).

Recursively visits each element in the set.

Source

fn visit_record( &mut self, fields: &Arc<BTreeMap<SmolStr, Expr>>, _loc: Option<&Loc>, ) -> Option<Self::Output>

Visits a record literal expression (e.g., { "key": value }).

Recursively visits the value of each field in the record.

Implementors§