(exprID int64, function string, target ast.Expr, args ...ast.Expr)
| 957 | } |
| 958 | |
| 959 | func (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 | |
| 993 | func (p *parser) checkAndIncrementRecursionDepth() { |
| 994 | p.recursionDepth++ |
no test coverage detected