CEL.Expr (CEL v0.2.0)

Copy Markdown View Source

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):

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

What CEL.Expr.Ident's scope says a name is.

t()

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

map_entry()

@type map_entry() :: %{key: t(), value: t(), optional: boolean()}

An entry of a CEL.Expr.MapLiteral.

message_field()

@type message_field() :: %{field: String.t(), value: t(), optional: boolean()}

A field of a CEL.Expr.MessageLiteral.

scope()

@type scope() :: :var | :local | :type | :enum

What CEL.Expr.Ident's scope says a name is.

t()

Any node.

type()

@type type() :: CEL.Type.t() | nil

A node's checked type, or nil for a node the checker did not type.

Functions

children(comprehension)

@spec children(t()) :: [t()]

Returns the direct children of a node in evaluation order.

filter(node, fun)

@spec filter(t(), (t() -> as_boolean(term()))) :: [t()]

Returns the nodes, in visiting order, for which fun returns a truthy value.

reduce(node, acc, fun)

@spec reduce(t(), acc, (t(), acc -> acc)) :: acc when acc: term()

Folds fun over a node and its descendants, visiting each node before its children.