MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Compile

Function Compile

cel/cel.go:26–40  ·  view source on GitHub ↗

Compile is a convenience function that constructs a new Env using the provided EnvOption values, compiles the expression string, and plans an executable Program. Warning: Creating a new environment for every compilation is expensive. Environment setup should be done once and shared across expressio

(expression string, opts ...EnvOption)

Source from the content-addressed store, hash-verified

24// Warning: Creating a new environment for every compilation is expensive. Environment setup should be done once
25// and shared across expression compilations when the options remain the same.
26func Compile(expression string, opts ...EnvOption) (Program, error) {
27 env, err := NewEnv(opts...)
28 if err != nil {
29 return nil, err
30 }
31 ast, iss := env.Compile(expression)
32 if iss.Err() != nil {
33 return nil, iss.Err()
34 }
35 prg, err := env.Program(ast, EvalOptions(OptOptimize))
36 if err != nil {
37 return nil, err
38 }
39 return prg, nil
40}

Callers 15

Example_cel_CommonErrorsFunction · 0.92
Example_cel_CustomMacrosFunction · 0.92
Example_cel_TernaryFunction · 0.92
Example_cel_MacrosFunction · 0.92
Example_cel_ArithmeticFunction · 0.92
Example_cel_ComparisonFunction · 0.92
Example_cel_NullFunction · 0.92

Calls 5

CompileMethod · 0.95
ProgramMethod · 0.95
EvalOptionsFunction · 0.85
ErrMethod · 0.80
NewEnvFunction · 0.70

Tested by 15

Example_cel_CommonErrorsFunction · 0.74
Example_cel_CustomMacrosFunction · 0.74
Example_cel_TernaryFunction · 0.74
Example_cel_MacrosFunction · 0.74
Example_cel_ArithmeticFunction · 0.74
Example_cel_ComparisonFunction · 0.74
Example_cel_NullFunction · 0.74