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

Method ProgramOptions

ext/bindings.go:109–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

107}
108
109func (lib *celBindings) ProgramOptions() []cel.ProgramOption {
110 if lib.version >= 1 {
111 celBlockPlan := func(i interpreter.InterpretableV2) (interpreter.InterpretableV2, error) {
112 call, ok := i.(interpreter.InterpretableCall)
113 if !ok {
114 return i, nil
115 }
116 switch call.Function() {
117 case "cel.@block":
118 args := call.Args()
119 if len(args) != 2 {
120 return nil, fmt.Errorf("cel.@block expects two arguments, but got %d", len(args))
121 }
122 expr := args[1]
123 // Non-empty block
124 if block, ok := args[0].(interpreter.InterpretableConstructor); ok {
125 slotExprs := block.InitVals()
126 return newDynamicBlock(slotExprs, expr), nil
127 }
128 // Constant valued block which can happen during runtime optimization.
129 if cons, ok := args[0].(interpreter.InterpretableConst); ok {
130 if cons.Value().Type() == types.ListType {
131 l := cons.Value().(traits.Lister)
132 if l.Size().Equal(types.IntZero) == types.True {
133 return args[1], nil
134 }
135 return newConstantBlock(l, expr), nil
136 }
137 }
138 return nil, errors.New("cel.@block expects a list constructor as the first argument")
139 default:
140 return i, nil
141 }
142 }
143 return []cel.ProgramOption{cel.CustomDecoratorV2(celBlockPlan)}
144 }
145 return []cel.ProgramOption{}
146}
147
148type blockValidationExemption struct{}
149

Callers

nothing calls this directly

Calls 11

CustomDecoratorV2Function · 0.92
newDynamicBlockFunction · 0.85
newConstantBlockFunction · 0.85
NewMethod · 0.80
FunctionMethod · 0.65
ArgsMethod · 0.65
InitValsMethod · 0.65
TypeMethod · 0.65
ValueMethod · 0.65
EqualMethod · 0.65
SizeMethod · 0.65

Tested by

no test coverage detected