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

Method ProgramOptions

ext/bindings.go:109–149  ·  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 if len(slotExprs) == 0 {
127 return expr, nil
128 }
129 return newDynamicBlock(slotExprs, expr), nil
130 }
131 // Constant valued block which can happen during runtime optimization.
132 if cons, ok := args[0].(interpreter.InterpretableConst); ok {
133 if cons.Value().Type() == types.ListType {
134 l := cons.Value().(traits.Lister)
135 if l.Size().Equal(types.IntZero) == types.True {
136 return args[1], nil
137 }
138 return newConstantBlock(l, expr), nil
139 }
140 }
141 return nil, errors.New("cel.@block expects a list constructor as the first argument")
142 default:
143 return i, nil
144 }
145 }
146 return []cel.ProgramOption{cel.CustomDecoratorV2(celBlockPlan)}
147 }
148 return []cel.ProgramOption{}
149}
150
151type blockValidationExemption struct{}
152

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