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

Function celCompreVar

conformance/conformance_test.go:385–402  ·  view source on GitHub ↗
(funcName, varPrefix string)

Source from the content-addressed store, hash-verified

383}
384
385func celCompreVar(funcName, varPrefix string) cel.MacroFactory {
386 return func(mef cel.MacroExprFactory, target ast.Expr, args []ast.Expr) (ast.Expr, *cel.Error) {
387 if !isCELNamespace(target) {
388 return nil, nil
389 }
390 depth := args[0]
391 if !isNonNegativeInt(depth) {
392 return depth, mef.NewError(depth.ID(), fmt.Sprintf("%s requires two non-negative int constant args", funcName))
393 }
394 unique := args[1]
395 if !isNonNegativeInt(unique) {
396 return unique, mef.NewError(unique.ID(), fmt.Sprintf("%s requires two non-negative int constant args", funcName))
397 }
398 depthVal := depth.AsLiteral().(types.Int)
399 uniqueVal := unique.AsLiteral().(types.Int)
400 return mef.NewIdent(fmt.Sprintf("%s:%d:%d", varPrefix, depthVal, uniqueVal)), nil
401 }
402}
403
404func isCELNamespace(target ast.Expr) bool {
405 return target.Kind() == ast.IdentKind && target.AsIdent() == "cel"

Callers 1

CompileOptionsMethod · 0.85

Calls 6

isCELNamespaceFunction · 0.85
isNonNegativeIntFunction · 0.85
NewErrorMethod · 0.65
IDMethod · 0.65
AsLiteralMethod · 0.65
NewIdentMethod · 0.65

Tested by

no test coverage detected