| 50 | } // namespace |
| 51 | |
| 52 | std::vector<Macro> bindings_macros() { |
| 53 | absl::StatusOr<Macro> cel_bind = Macro::Receiver( |
| 54 | kBind, 3, |
| 55 | [](MacroExprFactory& factory, Expr& target, |
| 56 | absl::Span<Expr> args) -> absl::optional<Expr> { |
| 57 | if (!IsTargetNamespace(target)) { |
| 58 | return absl::nullopt; |
| 59 | } |
| 60 | if (!args[0].has_ident_expr()) { |
| 61 | return factory.ReportErrorAt( |
| 62 | args[0], "cel.bind() variable name must be a simple identifier"); |
| 63 | } |
| 64 | auto var_name = args[0].ident_expr().name(); |
| 65 | return factory.NewComprehension(kUnusedIterVar, factory.NewList(), |
| 66 | std::move(var_name), std::move(args[1]), |
| 67 | factory.NewBoolConst(false), |
| 68 | std::move(args[0]), std::move(args[2])); |
| 69 | }); |
| 70 | return {*cel_bind}; |
| 71 | } |
| 72 | |
| 73 | CompilerLibrary BindingsCompilerLibrary() { |
| 74 | return CompilerLibrary("cel.lib.ext.bindings", &ConfigureParser); |