cel_expr/env

Environments: what an expression is compiled with (see cel_expr/program). An environment that declares variables type-checks the expressions it compiles, so that one that refers to anything undeclared, or calls a function with the wrong types, fails to compile rather than to evaluate:

let env =
  env.new()
  |> env.variable("name", types.String)
  |> env.extensions([env.Strings])
let assert Ok(program) = program.compile("name.upperAscii()", env)

Types

An environment.

pub opaque type Env

An extension library, as cel-go has them at their latest versions, with the macros and syntax they bring.

pub type Extension {
  Bindings
  Comprehensions
  Encoders
  Lists
  Math
  Network
  Optional
  Protos
  Sets
  Strings
}

Constructors

  • Bindings

    cel.bind, and cel.@block.

  • Comprehensions

    Two-variable comprehensions: all, exists and existsOne with two variables, and transformList, transformMap and transformMapEntry.

  • Encoders

    base64.encode and base64.decode.

  • Lists

    slice, flatten, sort, sortBy, lists.range, reverse, distinct, hasOnly, hasAny, hasAll and hasExactly.

  • Math

    math.greatest, math.least, rounding, math.abs, math.sign, math.sqrt, and bitwise operations.

  • Network

    net.IP and net.CIDR.

  • Optional

    Optional types, with their syntax: a.?b, a[?b], [?x] and {?k: v}.

  • Protos

    proto.getExt and proto.hasExt.

  • Sets

    sets.contains, sets.equivalent and sets.intersects.

  • Strings

    The strings extension: charAt, indexOf, format, split and the rest.

A custom function’s implementation: its arguments’ values, a receiver’s first, give its result, or an error that fails the expression with its message.

pub type Implementation =
  fn(List(value.Value)) -> Result(value.Value, String)

An overload of a custom function: its arguments’ types, a receiver’s first, and its result’s type.

pub type Overload {
  Overload(arguments: List(types.Type), result: types.Type)
}

Constructors

What runs matches, whose patterns have RE2’s syntax.

pub type Regex {
  Re
  Re2
}

Constructors

  • Re

    OTP’s re, the default, which refuses patterns it would run with another meaning than RE2’s, such as lookarounds and backreferences, and fails matches that backtrack too far.

  • Re2

    RE2 itself, with its exact meaning and in time linear in the subject, through the NIF of the re2 package, which an application that wants it depends on. Without it, compiling fails.

How a function is called: f(x), or x.f(), whose receiver is its first argument.

pub type Style {
  Global
  Receiver
}

Constructors

  • Global
  • Receiver

Values

pub fn checked(env: Env) -> Env

Type-checks the expressions the environment compiles, even if it declares no variables.

pub fn constant(
  env: Env,
  name: String,
  value: value.Value,
) -> Env

Binds a variable to a value known when an expression is compiled, which compiling folds into it. A checked environment declares it with variable too.

pub fn container(env: Env, container: String) -> Env

The protobuf package that names of messages and enums are resolved in.

pub fn extensions(env: Env, extensions: List(Extension)) -> Env

Adds extension libraries.

pub fn function(
  env: Env,
  name: String,
  style: Style,
  overloads: List(Overload),
  implementation: fn(List(value.Value)) -> Result(
    value.Value,
    String,
  ),
) -> Env

Adds a custom function, or replaces a standard one, of the given name and style, with its overloads for a checked environment, which needs them to compile calls of it.

pub fn new() -> Env

An environment with the standard library and nothing else, which does not type-check.

pub fn provider(env: Env, provider: pb.Provider) -> Env

The provider of the protobuf messages expressions read and make.

pub fn regex(env: Env, regex: Regex) -> Env

What runs matches: Re unless this says otherwise.

pub fn variable(env: Env, name: String, type_: types.Type) -> Env

Declares a variable’s type, which type-checks the expressions the environment compiles.

✨ Search Document