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

Function decRegexOptimizer

interpreter/decorators.go:133–172  ·  view source on GitHub ↗

decRegexOptimizer compiles regex pattern string constants.

(regexOptimizations ...*RegexOptimization)

Source from the content-addressed store, hash-verified

131
132// decRegexOptimizer compiles regex pattern string constants.
133func decRegexOptimizer(regexOptimizations ...*RegexOptimization) InterpretableDecoratorV2 {
134 functionMatchMap := make(map[string]*RegexOptimization)
135 overloadMatchMap := make(map[string]*RegexOptimization)
136 for _, m := range regexOptimizations {
137 functionMatchMap[m.Function] = m
138 if m.OverloadID != "" {
139 overloadMatchMap[m.OverloadID] = m
140 }
141 }
142
143 return func(i InterpretableV2) (InterpretableV2, error) {
144 call, ok := i.(InterpretableCall)
145 if !ok {
146 return i, nil
147 }
148
149 var matcher *RegexOptimization
150 var found bool
151 if call.OverloadID() != "" {
152 matcher, found = overloadMatchMap[call.OverloadID()]
153 }
154 if !found {
155 matcher, found = functionMatchMap[call.Function()]
156 }
157 if !found || matcher.RegexIndex >= len(call.Args()) {
158 return i, nil
159 }
160 args := call.Args()
161 regexArg := args[matcher.RegexIndex]
162 regexStr, isConst := regexArg.(InterpretableConst)
163 if !isConst {
164 return i, nil
165 }
166 pattern, ok := regexStr.Value().(types.String)
167 if !ok {
168 return i, nil
169 }
170 return matcher.Factory(call, string(pattern))
171 }
172}
173
174func decRegexProgramSizeLimit(limit int) InterpretableDecoratorV2 {
175 return func(i InterpretableV2) (InterpretableV2, error) {

Callers 1

CompileRegexConstantsFunction · 0.85

Calls 4

OverloadIDMethod · 0.65
FunctionMethod · 0.65
ArgsMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected