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

Method expandMacro

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

Source from the content-addressed store, hash-verified

957}
958
959func (p *parser) expandMacro(exprID int64, function string, target ast.Expr, args ...ast.Expr) (ast.Expr, bool) {
960 macro, found := p.macros[makeMacroKey(function, len(args), target != nil)]
961 if !found {
962 macro, found = p.macros[makeVarArgMacroKey(function, target != nil)]
963 if !found {
964 return nil, false
965 }
966 }
967 eh := exprHelperPool.Get().(*exprHelper)
968 defer exprHelperPool.Put(eh)
969 eh.parserHelper = p.helper
970 eh.id = exprID
971 expr, err := macro.Expander()(eh, target, args)
972 // An error indicates that the macro was matched, but the arguments were not well-formed.
973 if err != nil {
974 loc := err.Location
975 if loc == nil {
976 loc = p.helper.getLocation(exprID)
977 }
978 p.helper.deleteID(exprID)
979 return p.reportError(loc, "%s", err.Message), true
980 }
981 // A nil value from the macro indicates that the macro implementation decided that
982 // an expansion should not be performed.
983 if expr == nil {
984 return nil, false
985 }
986 if p.populateMacroCalls {
987 p.helper.addMacroCall(expr.ID(), function, target, args...)
988 }
989 p.helper.deleteID(exprID)
990 return expr, true
991}
992
993func (p *parser) checkAndIncrementRecursionDepth() {
994 p.recursionDepth++

Callers 2

globalCallOrMacroMethod · 0.95
receiverCallOrMacroMethod · 0.95

Calls 9

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

Tested by

no test coverage detected