A read-only view of a checked CEL expression, in the spirit of cel-go's
common/ast. Get one with CEL.Checked.expr/1.
The view is a tree of node structs, each with the expression's id and its
checked type (a CEL.Type.t/0, or nil for a node the checker did
not type):
CEL.Expr.Const— a literal.CEL.Expr.Ident— a variable, type or enum value, by full name.CEL.Expr.Select—operand.field,has(operand.field)andoperand.?field.CEL.Expr.Call— a function call, operator or enum constructor.CEL.Expr.MacroCall— a macro as written, such asl.exists(x, p)orcel.bind(v, init, body).CEL.Expr.ListLiteral,CEL.Expr.MapLiteralandCEL.Expr.MessageLiteral.CEL.Expr.Comprehension— the loop a macro expands to.
id is the one CEL.Checked.type/2, CEL.Checked.position/2 and
CEL.Checked.references/1 use.
Match on the structs to inspect the tree, and use reduce/3, filter/2 or
children/1 to walk it. They visit what the author wrote: a MacroCall's
target and arguments, not its expansion.
alias CEL.Expr.Call
checked
|> CEL.Checked.expr()
|> CEL.Expr.filter(&match?(%Call{function: "lookup"}, &1))The view is derived from the checked expression; evaluation does not read it, so it stays stable as the evaluator changes.
Summary
Types
An entry of a CEL.Expr.MapLiteral.
A field of a CEL.Expr.MessageLiteral.
What CEL.Expr.Ident's scope says a name is.
Any node.
A node's checked type, or nil for a node the checker did not type.
Functions
Returns the direct children of a node in evaluation order.
Returns the nodes, in visiting order, for which fun returns a truthy value.
Folds fun over a node and its descendants, visiting each node before its
children.
Types
An entry of a CEL.Expr.MapLiteral.
A field of a CEL.Expr.MessageLiteral.
@type scope() :: :var | :local | :type | :enum
What CEL.Expr.Ident's scope says a name is.
@type t() :: CEL.Expr.Const.t() | CEL.Expr.Ident.t() | CEL.Expr.Select.t() | CEL.Expr.Call.t() | CEL.Expr.ListLiteral.t() | CEL.Expr.MapLiteral.t() | CEL.Expr.MessageLiteral.t() | CEL.Expr.MacroCall.t() | CEL.Expr.Comprehension.t()
Any node.
@type type() :: CEL.Type.t() | nil
A node's checked type, or nil for a node the checker did not type.
Functions
Returns the direct children of a node in evaluation order.
@spec filter(t(), (t() -> as_boolean(term()))) :: [t()]
Returns the nodes, in visiting order, for which fun returns a truthy value.
Folds fun over a node and its descendants, visiting each node before its
children.