call_func(variable1, variable2)
()
| 758 | |
| 759 | // call_func(variable1, variable2) |
| 760 | func (p *Parser) parseCallExpression() (ast.Expression, error) { |
| 761 | // Ensure the current token is a valid identifier before proceeding. |
| 762 | if !p.currentTokenIs(token.IDENT) { |
| 763 | p.currentError(token.IDENT) |
| 764 | return nil, p.Error() |
| 765 | } |
| 766 | |
| 767 | // Create a new Identifier expression with the first token as the prefix. |
| 768 | call := &ast.Call{Name: p.currentToken} |
| 769 | |
| 770 | if !p.expectAndNext(token.LP) { |
| 771 | return nil, p.Error() |
| 772 | } |
| 773 | |
| 774 | // Check if there are no arguments |
| 775 | if p.peekTokenIs(token.RP) { |
| 776 | p.next() // consume the RP token |
| 777 | return call, nil |
| 778 | } |
| 779 | |
| 780 | p.next() |
| 781 | |
| 782 | // Parse the first argument |
| 783 | ident, err := p.parseIdentifierExpression() |
| 784 | if err != nil { |
| 785 | return nil, err |
| 786 | } |
| 787 | |
| 788 | i, ok := ident.(*ast.Identifier) |
| 789 | if !ok { |
| 790 | return nil, fmt.Errorf("expected identifier, got %T", ident) |
| 791 | } |
| 792 | call.Arguments = append(call.Arguments, *i) |
| 793 | |
| 794 | // Parse remaining arguments |
| 795 | for p.peekTokenIs(token.COMMA) { |
| 796 | p.next() |
| 797 | |
| 798 | if !p.expectAndNext(token.IDENT) { |
| 799 | return nil, p.Error() |
| 800 | } |
| 801 | |
| 802 | ident, err = p.parseIdentifierExpression() |
| 803 | if err != nil { |
| 804 | return nil, err |
| 805 | } |
| 806 | |
| 807 | i, ok = ident.(*ast.Identifier) |
| 808 | if !ok { |
| 809 | return nil, fmt.Errorf("expected identifier, got %T", ident) |
| 810 | } |
| 811 | call.Arguments = append(call.Arguments, *i) |
| 812 | } |
| 813 | |
| 814 | if !p.expectAndNext(token.RP) { |
| 815 | return nil, p.Error() |
| 816 | } |
| 817 |
no test coverage detected