Data Structures¶
Run-Time¶
An external client depends on the celpy.Environment
.
The celpy.Environment
builds the initial AST and the final runnable “program.”
The celpy.Environment
may also contain a type provider and type adapters.
The celpy.Environment
also builds
an celpy.evaluation.Activation
with the variable and function bindings
and the default package.
The celpy.evaluation.Activation
create a kind of chainmap for name
resolution. The chain has the following structure:
The end of the chain is the built-in defaults.
A layer on top of this can be provided as part of integration into some other app or framework.
The next layer is the “current” activation when evaluating a given expression. This often has command-line variables.
A transient top-most layer is used to create a local variable binding for the macro evaluations.
The AST is created by Lark from the CEL expression.
There are two celpy.Runner
implementations.
The
celpy.InterpretedRunner
walks the AST, creating the final result or exception.The
celpy.CompiledRunner
transforms the AST to remove empty rules. Then emits the result as a Python expression. It uses the Python internalcompile()
andeval()
functions to evaluate the expression.
CEL Types¶
There are ten extension types that wrap Python built-in types to provide the unique CEL semantics.
celtypes.BoolType
wrapsint
and creates additional type overload exceptions.celtypes.BytesType
wrapsbytes
it handles conversion fromceltypes.StringType
.celtypes.DoubleType
wrapsfloat
and creates additional type overload exceptions.celtypes.IntType
wrapsint
and adds a 64-bit signed range constraint.celtypes.UintType
wrapsint
and adds a 64-bit unsigned range constraint.celtypes.ListType
wrapslist
and includes some type overload exceptions.celtypes.MapType
wrapsdict
and includes some type overload exceptions. Additionally, theMapKeyTypes
type hint is the subset of types permitted as keys.celtypes.StringType
wrapsstr
and includes some type overload exceptions.celtypes.TimestampType
wrapsdatetime.datetime
and includes a number of conversions fromdatetime.datetime
,int
, andstr
values.celtypes.DurationType
wrapsdatetime.timedelta
and includes a number of conversions fromdatetime.timedelta
,int
, andstr
values.
Additionally, a celtypes.NullType
is defined, but does not seem to be needed. It hasn’t been deleted, yet.
but should be considered deprecated.