(funcName, varPrefix string)
| 382 | } |
| 383 | |
| 384 | func 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 | |
| 403 | func isCELNamespace(target ast.Expr) bool { |
| 404 | return target.Kind() == ast.IdentKind && target.AsIdent() == "cel" |
no test coverage detected