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

Method Validate

cel/validator.go:263–279  ·  view source on GitHub ↗

Validate searches the AST for uses of a given function name with a constant argument and performs a check on whether the argument is a valid literal value.

(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues)

Source from the content-addressed store, hash-verified

261// Validate searches the AST for uses of a given function name with a constant argument and performs a check
262// on whether the argument is a valid literal value.
263func (v formatValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) {
264 root := ast.NavigateAST(a)
265 funcCalls := ast.MatchDescendants(root, ast.FunctionMatcher(v.funcName))
266 for _, call := range funcCalls {
267 callArgs := call.AsCall().Args()
268 if len(callArgs) <= v.argNum {
269 continue
270 }
271 litArg := callArgs[v.argNum]
272 if litArg.Kind() != ast.LiteralKind {
273 continue
274 }
275 if err := v.check(e, call, litArg); err != nil {
276 iss.ReportErrorAtID(litArg.ID(), "invalid %s argument", v.funcName)
277 }
278 }
279}
280
281func evalCall(env *Env, call, arg ast.Expr) error {
282 ast := &Ast{impl: ast.NewAST(call, ast.NewSourceInfo(nil))}

Callers

nothing calls this directly

Calls 9

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
FunctionMatcherFunction · 0.92
checkMethod · 0.80
ArgsMethod · 0.65
AsCallMethod · 0.65
KindMethod · 0.65
ReportErrorAtIDMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected