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)
| 386 | // environment `env` and determine whether the resulting type of the expression |
| 387 | // matches the `exprType` provided as input. |
| 388 | func 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 |