Parse a cel expression and evaluate it against the given activation and arena.
| 81 | // Parse a cel expression and evaluate it against the given activation and |
| 82 | // arena. |
| 83 | absl::StatusOr<bool> EvalCheckedExpr(const CheckedExpr& checked_expr, |
| 84 | const Activation& activation, |
| 85 | google::protobuf::Arena* arena) { |
| 86 | // Setup a default environment for building expressions. |
| 87 | InterpreterOptions options; |
| 88 | std::unique_ptr<CelExpressionBuilder> builder = CreateCelExpressionBuilder( |
| 89 | google::protobuf::DescriptorPool::generated_pool(), |
| 90 | google::protobuf::MessageFactory::generated_factory(), options); |
| 91 | CEL_RETURN_IF_ERROR( |
| 92 | RegisterBuiltinFunctions(builder->GetRegistry(), options)); |
| 93 | |
| 94 | // Note, the expression_plan below is reusable for different inputs, but we |
| 95 | // create one just in time for evaluation here. |
| 96 | CEL_ASSIGN_OR_RETURN(std::unique_ptr<CelExpression> expression_plan, |
| 97 | builder->CreateExpression(&checked_expr)); |
| 98 | |
| 99 | CEL_ASSIGN_OR_RETURN(CelValue result, |
| 100 | expression_plan->Evaluate(activation, arena)); |
| 101 | |
| 102 | if (bool value; result.GetValue(&value)) { |
| 103 | return value; |
| 104 | } else if (const CelError * value; result.GetValue(&value)) { |
| 105 | return *value; |
| 106 | } else { |
| 107 | return absl::InvalidArgumentError(absl::StrCat( |
| 108 | "expected 'bool' result got '", result.DebugString(), "'")); |
| 109 | } |
| 110 | } |
| 111 | } // namespace |
| 112 | |
| 113 | absl::StatusOr<bool> CompileAndEvaluateWithBoolVar(absl::string_view cel_expr, |
no test coverage detected