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

Function celCompreVar

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

Source from the content-addressed store, hash-verified

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