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

Method expandMacro

parser/parser.go:967–1009  ·  view source on GitHub ↗
(exprID int64, function string, target ast.Expr, args ...ast.Expr)

Source from the content-addressed store, hash-verified

965}
966
967func (p *parser) expandMacro(exprID int64, function string, target ast.Expr, args ...ast.Expr) (ast.Expr, bool) {
968 macro, found := p.macros[makeMacroKey(function, len(args), target != nil)]
969 if !found {
970 macro, found = p.macros[makeVarArgMacroKey(function, target != nil)]
971 if !found {
972 return nil, false
973 }
974 }
975 if int(p.helper.expressionCount()) > p.maxExpressionNodeCount {
976 loc := p.helper.getLocation(exprID)
977 p.helper.deleteID(exprID)
978 return p.reportError(loc, "expression count exceeds limit of %d while expanding macro '%s'", p.maxExpressionNodeCount, function), true
979 }
980 eh := exprHelperPool.Get().(*exprHelper)
981 defer exprHelperPool.Put(eh)
982 eh.parserHelper = p.helper
983 eh.id = exprID
984 expr, err := macro.Expander()(eh, target, args)
985 if int(p.helper.expressionCount()) > p.maxExpressionNodeCount {
986 loc := p.helper.getLocation(exprID)
987 p.helper.deleteID(exprID)
988 return p.reportError(loc, "expression count exceeds limit of %d while expanding macro '%s'", p.maxExpressionNodeCount, function), true
989 }
990 // An error indicates that the macro was matched, but the arguments were not well-formed.
991 if err != nil {
992 loc := err.Location
993 if loc == nil {
994 loc = p.helper.getLocation(exprID)
995 }
996 p.helper.deleteID(exprID)
997 return p.reportError(loc, "%s", err.Message), true
998 }
999 // A nil value from the macro indicates that the macro implementation decided that
1000 // an expansion should not be performed.
1001 if expr == nil {
1002 return nil, false
1003 }
1004 if p.populateMacroCalls {
1005 p.helper.addMacroCall(expr.ID(), function, target, args...)
1006 }
1007 p.helper.deleteID(exprID)
1008 return expr, true
1009}
1010
1011func (p *parser) checkAndIncrementRecursionDepth() {
1012 p.recursionDepth++

Callers 2

globalCallOrMacroMethod · 0.95
receiverCallOrMacroMethod · 0.95

Calls 10

reportErrorMethod · 0.95
makeMacroKeyFunction · 0.85
makeVarArgMacroKeyFunction · 0.85
expressionCountMethod · 0.80
getLocationMethod · 0.80
deleteIDMethod · 0.80
addMacroCallMethod · 0.80
GetMethod · 0.65
ExpanderMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected