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

Method AddFunctionDecls

common/env/env.go:146–177  ·  view source on GitHub ↗

AddFunctionDecls adds one or more functions to the config, converting them to serializable values first. FunctionDecl inputs are expected to be well-formed.

(funcs ...*decls.FunctionDecl)

Source from the content-addressed store, hash-verified

144//
145// FunctionDecl inputs are expected to be well-formed.
146func (c *Config) AddFunctionDecls(funcs ...*decls.FunctionDecl) *Config {
147 convFuncs := make([]*Function, len(funcs))
148 for i, fn := range funcs {
149 if fn == nil {
150 continue
151 }
152 overloads := make([]*Overload, 0, len(fn.OverloadDecls()))
153 for _, o := range fn.OverloadDecls() {
154 overloadID := o.ID()
155 args := make([]*TypeDesc, 0, len(o.ArgTypes()))
156 for _, a := range o.ArgTypes() {
157 args = append(args, SerializeTypeDesc(a))
158 }
159 ret := SerializeTypeDesc(o.ResultType())
160 var overload *Overload
161 if o.IsMemberFunction() {
162 overload = NewMemberOverload(overloadID, args[0], args[1:], ret)
163 } else {
164 overload = NewOverload(overloadID, args, ret)
165 }
166 exampleCount := len(o.Examples())
167 if exampleCount > 0 {
168 overload.Examples = o.Examples()
169 }
170 overloads = append(overloads, overload)
171 }
172 cf := NewFunction(fn.Name(), overloads...)
173 cf.Description = fn.Description()
174 convFuncs[i] = cf
175 }
176 return c.AddFunctions(convFuncs...)
177}
178
179// AddFunctions adds one or more functions to the config.
180func (c *Config) AddFunctions(funcs ...*Function) *Config {

Callers 2

ToConfigMethod · 0.95

Calls 13

AddFunctionsMethod · 0.95
SerializeTypeDescFunction · 0.85
NewMemberOverloadFunction · 0.85
OverloadDeclsMethod · 0.80
ArgTypesMethod · 0.80
ExamplesMethod · 0.80
NewOverloadFunction · 0.70
NewFunctionFunction · 0.70
IDMethod · 0.65
IsMemberFunctionMethod · 0.65
NameMethod · 0.65
DescriptionMethod · 0.65

Tested by 1