CEL.Program (CEL v0.2.0)

Copy Markdown View Source

A checked CEL expression together with the CEL.Env it was checked against, ready to evaluate any number of times.

env = CEL.Env.build(vars: [name: :string])

{:ok, program} = CEL.compile(~s|"hello, " + name|, env)
CEL.Program.eval(program, %{name: "world"})
#=> {:ok, {:string, "hello, world"}}

Get one from CEL.compile/2, or with new/2 from a CEL.Checked you already have. Literal regular expressions are compiled once, here.

Summary

Functions

Evaluates a compiled program with the supplied variable bindings.

Evaluates a compiled program, raising on errors and unknown results.

Bundles a previously checked expression with the environment it was checked against, returning a Program ready for eval/2.

Types

t()

@type t() :: %CEL.Program{
  checked: CEL.Checked.t(),
  env: CEL.Env.t(),
  regexes: %{required(CEL.Checked.expr_id()) => Regex.t()}
}

Functions

eval(program, values \\ %{})

@spec eval(t(), map() | keyword()) ::
  {:ok, CEL.Value.t()} | {:unknown, CEL.Unknown.t()} | {:error, CEL.Error.t()}

Evaluates a compiled program with the supplied variable bindings.

eval!(program, values \\ %{})

@spec eval!(t(), map() | keyword()) :: CEL.Value.t()

Evaluates a compiled program, raising on errors and unknown results.

new(checked, env)

@spec new(CEL.Checked.t(), CEL.Env.t()) :: t()

Bundles a previously checked expression with the environment it was checked against, returning a Program ready for eval/2.

Most callers should use CEL.compile/2, which parses, checks, and bundles in one call. Use this constructor when you already hold a CEL.Checked and the matching CEL.Env — for example, to cache the check phase and re-bundle programs with different runtime bindings.