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

Method expandMacro

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

Source from the content-addressed store, hash-verified

355}
356
357func (p *prattParserWorker) expandMacro(exprID int64, function string, target ast.Expr, args ...ast.Expr) (ast.Expr, bool) {
358 if len(p.macros) == 0 {
359 return nil, false
360 }
361 macro, found := p.macros[makeMacroKey(function, len(args), target != nil)]
362 if !found {
363 macro, found = p.macros[makeVarArgMacroKey(function, target != nil)]
364 if !found {
365 return nil, false
366 }
367 }
368 if int(p.helper.expressionCount()) > p.maxExpressionNodeCount {
369 loc := p.helper.getLocation(exprID)
370 p.helper.deleteID(exprID)
371 return p.reportError(loc, "expression count exceeds limit of %d while expanding macro '%s'", p.maxExpressionNodeCount, function), true
372 }
373 eh := exprHelperPool.Get().(*exprHelper)
374 eh.parserHelper = p.helper
375 eh.id = exprID
376 expr, err := macro.Expander()(eh, target, args)
377 exprHelperPool.Put(eh)
378 if int(p.helper.expressionCount()) > p.maxExpressionNodeCount {
379 loc := p.helper.getLocation(exprID)
380 p.helper.deleteID(exprID)
381 return p.reportError(loc, "expression count exceeds limit of %d while expanding macro '%s'", p.maxExpressionNodeCount, function), true
382 }
383 if err != nil {
384 loc := err.Location
385 if loc == nil {
386 loc = p.helper.getLocation(exprID)
387 }
388 p.helper.deleteID(exprID)
389 return p.reportError(loc, "%s", err.Message), true
390 }
391 if expr == nil {
392 return nil, false
393 }
394 if p.populateMacroCalls {
395 p.helper.addMacroCall(expr.ID(), function, target, args...)
396 }
397 p.helper.deleteID(exprID)
398 return expr, true
399}
400
401func (p *prattParserWorker) normalizeIdent(tok token, allowQuoted bool, isQuoted *bool) string {
402 if isQuoted != nil {

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