parseCall parses a function call. This function assumes the function name and LPAREN have been consumed.
(name string)
| 520 | // parseCall parses a function call. |
| 521 | // This function assumes the function name and LPAREN have been consumed. |
| 522 | func (p *Parser) parseCall(name string) (*Call, error) { |
| 523 | name = strings.ToLower(name) |
| 524 | // If there's a right paren then just return immediately. |
| 525 | if tok, _, _ := p.scan(); tok == RPAREN { |
| 526 | return &Call{Name: name}, nil |
| 527 | } |
| 528 | p.unscan() |
| 529 | |
| 530 | // Otherwise parse function call arguments. |
| 531 | var args []Expr |
| 532 | for { |
| 533 | // Parse an expression argument. |
| 534 | arg, err := p.ParseExpr(0) |
| 535 | if err != nil { |
| 536 | return nil, err |
| 537 | } |
| 538 | args = append(args, arg) |
| 539 | |
| 540 | // If there's not a comma next then stop parsing arguments. |
| 541 | if tok, _, _ := p.scan(); tok != COMMA { |
| 542 | p.unscan() |
| 543 | break |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | // There should be a right parentheses at the end. |
| 548 | if tok, pos, lit := p.scan(); tok != RPAREN { |
| 549 | return nil, newParseError(tokstr(tok, lit), []string{")"}, pos) |
| 550 | } |
| 551 | |
| 552 | return &Call{Name: name, Args: args}, nil |
| 553 | } |
| 554 | |
| 555 | // scan returns the next token from the underlying scanner. |
| 556 | func (p *Parser) scan() (tok Token, pos Pos, lit string) { return p.s.Scan() } |
no test coverage detected