MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / parseFunction

Method parseFunction

pkg/filter/ql/parser.go:494–543  ·  view source on GitHub ↗

parseFunction parses a function call. This method assumes the function name and LPAREN have been consumed.

(name string)

Source from the content-addressed store, hash-verified

492// parseFunction parses a function call. This method assumes
493// the function name and LPAREN have been consumed.
494func (p *Parser) parseFunction(name string) (*Function, error) {
495 name = strings.ToLower(name)
496 args := make([]Expr, 0)
497
498 // If there's a right paren then just return immediately.
499 // This is the case for functions without arguments
500 if tok, _, _ := p.scan(); tok == Rparen {
501 fn := &Function{Name: name}
502 if err := fn.validate(); err != nil {
503 return nil, err
504 }
505 return fn, nil
506 }
507 p.unscan()
508
509 arg, err := p.ParseExpr()
510 if err != nil {
511 return nil, err
512 }
513 args = append(args, arg)
514
515 // Parse additional function arguments if there is a comma.
516 for {
517 // If there's not a comma, stop parsing arguments.
518 if tok, _, _ := p.scanIgnoreWhitespace(); tok != Comma {
519 p.unscan()
520 break
521 }
522
523 // Parse an expression argument.
524 arg, err := p.ParseExpr()
525 if err != nil {
526 return nil, err
527 }
528 args = append(args, arg)
529 }
530
531 // There should be a right parentheses at the end.
532 if tok, pos, lit := p.scan(); tok != Rparen {
533 return nil, newParseError(tokstr(tok, lit), []string{")"}, pos, p.expr)
534 }
535
536 fn := &Function{Name: name, Args: args}
537
538 if err := fn.validate(); err != nil {
539 return nil, err
540 }
541
542 return fn, nil
543}
544
545// parseDuration parses a string and returns a duration literal.
546func (p *Parser) parseDuration() (time.Duration, error) {

Callers 1

parseUnaryExprMethod · 0.95

Calls 7

scanMethod · 0.95
validateMethod · 0.95
unscanMethod · 0.95
ParseExprMethod · 0.95
scanIgnoreWhitespaceMethod · 0.95
newParseErrorFunction · 0.85
tokstrFunction · 0.85

Tested by

no test coverage detected