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

Function compile

codelab/solution/codelab.go:388–399  ·  view source on GitHub ↗

Functions to assist with CEL execution. compile will parse and check an expression `expr` against a given environment `env` and determine whether the resulting type of the expression matches the `exprType` provided as input.

(env *cel.Env, expr string, celType *cel.Type)

Source from the content-addressed store, hash-verified

386// environment `env` and determine whether the resulting type of the expression
387// matches the `exprType` provided as input.
388func compile(env *cel.Env, expr string, celType *cel.Type) *cel.Ast {
389 ast, iss := env.Compile(expr)
390 if iss.Err() != nil {
391 glog.Exit(iss.Err())
392 }
393 if !reflect.DeepEqual(ast.OutputType(), celType) {
394 glog.Exitf(
395 "Got %v, wanted %v result type", ast.OutputType(), celType)
396 }
397 fmt.Printf("%s\n\n", strings.ReplaceAll(expr, "\t", " "))
398 return ast
399}
400
401// eval will evaluate a given program `prg` against a set of variables `vars`
402// and return the output, eval details (optional), or error that results from

Callers 7

exercise2Function · 0.70
exercise3Function · 0.70
exercise4Function · 0.70
exercise5Function · 0.70
exercise6Function · 0.70
exercise7Function · 0.70
exercise8Function · 0.70

Calls 3

ErrMethod · 0.80
CompileMethod · 0.65
OutputTypeMethod · 0.45

Tested by

no test coverage detected