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

Method CompileOptions

ext/regex.go:136–167  ·  view source on GitHub ↗

CompileOptions implements the cel.Library interface method.

()

Source from the content-addressed store, hash-verified

134
135// CompileOptions implements the cel.Library interface method.
136func (r *regexLib) CompileOptions() []cel.EnvOption {
137 optionalTypesEnabled := func(env *cel.Env) (*cel.Env, error) {
138 if !env.HasLibrary("cel.lib.optional") {
139 return nil, errors.New("regex library requires the optional library")
140 }
141 return env, nil
142 }
143 opts := []cel.EnvOption{
144 cel.Function(regexExtract,
145 cel.Overload("regex_extract_string_string", []*cel.Type{cel.StringType, cel.StringType}, cel.OptionalType(cel.StringType),
146 cel.BinaryBinding(extract))),
147
148 cel.Function(regexExtractAll,
149 cel.Overload("regex_extractAll_string_string", []*cel.Type{cel.StringType, cel.StringType}, cel.ListType(cel.StringType),
150 cel.BinaryBinding(extractAll))),
151
152 cel.Function(regexReplace,
153 cel.Overload("regex_replace_string_string_string", []*cel.Type{cel.StringType, cel.StringType, cel.StringType}, cel.StringType,
154 cel.FunctionBinding(regReplace)),
155 cel.Overload("regex_replace_string_string_string_int", []*cel.Type{cel.StringType, cel.StringType, cel.StringType, cel.IntType}, cel.StringType,
156 cel.FunctionBinding((regReplaceN))),
157 ),
158 cel.CostEstimatorOptions(
159 checker.OverloadCostEstimate("regex_extract_string_string", estimateExtractCost()),
160 checker.OverloadCostEstimate("regex_extractAll_string_string", estimateExtractAllCost()),
161 checker.OverloadCostEstimate("regex_replace_string_string_string", estimateReplaceCost()),
162 checker.OverloadCostEstimate("regex_replace_string_string_string_int", estimateReplaceCost()),
163 ),
164 cel.EnvOption(optionalTypesEnabled),
165 }
166 return opts
167}
168
169// ProgramOptions implements the cel.Library interface method
170func (r *regexLib) ProgramOptions() []cel.ProgramOption {

Callers

nothing calls this directly

Calls 12

FunctionFunction · 0.92
OverloadFunction · 0.92
BinaryBindingFunction · 0.92
FunctionBindingFunction · 0.92
CostEstimatorOptionsFunction · 0.92
OverloadCostEstimateFunction · 0.92
EnvOptionFuncType · 0.92
estimateExtractCostFunction · 0.85
estimateExtractAllCostFunction · 0.85
estimateReplaceCostFunction · 0.85
HasLibraryMethod · 0.80
NewMethod · 0.80

Tested by

no test coverage detected