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

Function NewCompiler

tools/compiler/compiler.go:120–143  ·  view source on GitHub ↗

NewCompiler creates a new compiler with a set of functional options.

(opts ...any)

Source from the content-addressed store, hash-verified

118
119// NewCompiler creates a new compiler with a set of functional options.
120func NewCompiler(opts ...any) (Compiler, error) {
121 c := &compiler{
122 envOptions: []cel.EnvOption{},
123 policyParserOptions: []policy.ParserOption{},
124 policyCompilerOptions: []policy.CompilerOption{},
125 policyMetadataEnvOptions: []PolicyMetadataEnvOption{},
126 }
127 for _, opt := range opts {
128 switch opt := opt.(type) {
129 case cel.EnvOption:
130 c.envOptions = append(c.envOptions, opt)
131 case policy.ParserOption:
132 c.policyParserOptions = append(c.policyParserOptions, opt)
133 case policy.CompilerOption:
134 c.policyCompilerOptions = append(c.policyCompilerOptions, opt)
135 case PolicyMetadataEnvOption:
136 c.policyMetadataEnvOptions = append(c.policyMetadataEnvOptions, opt)
137 default:
138 return nil, fmt.Errorf("unsupported compiler option: %v", opt)
139 }
140 }
141 c.envOptions = append(c.envOptions, extensionOpt())
142 return c, nil
143}
144
145func extensionOpt() cel.EnvOption {
146 return func(e *cel.Env) (*cel.Env, error) {

Callers 4

TestCompilerFunction · 0.92

Calls 1

extensionOptFunction · 0.85

Tested by 4

TestCompilerFunction · 0.74