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 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
-
Bindingscel.bind, andcel.@block. -
ComprehensionsTwo-variable comprehensions:
all,existsandexistsOnewith two variables, andtransformList,transformMapandtransformMapEntry. -
Encodersbase64.encodeandbase64.decode. -
Listsslice,flatten,sort,sortBy,lists.range,reverse,distinct,hasOnly,hasAny,hasAllandhasExactly. -
Mathmath.greatest,math.least, rounding,math.abs,math.sign,math.sqrt, and bitwise operations. -
Networknet.IPandnet.CIDR. -
OptionalOptional types, with their syntax:
a.?b,a[?b],[?x]and{?k: v}. -
Protosproto.getExtandproto.hasExt. -
Setssets.contains,sets.equivalentandsets.intersects. -
StringsThe strings extension:
charAt,indexOf,format,splitand 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
-
Overload(arguments: List(types.Type), result: types.Type)
What runs matches, whose patterns have RE2’s syntax.
pub type Regex {
Re
Re2
}
Constructors
-
ReOTP’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. -
Re2RE2 itself, with its exact meaning and in time linear in the subject, through the NIF of the
re2package, which an application that wants it depends on. Without it, compiling fails.
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 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 variable(env: Env, name: String, type_: types.Type) -> Env
Declares a variable’s type, which type-checks the expressions the environment compiles.