parseIdentifier parses an identifier expression that may consist of one or more dot-separated identifiers, such as "x", "foo.bar", or "a.b.c.d". It constructs a new Identifier expression with the first token as the prefix and subsequent tokens as identifiers, and returns the resulting expression and
()
| 731 | // It constructs a new Identifier expression with the first token as the prefix and subsequent |
| 732 | // tokens as identifiers, and returns the resulting expression and any error encountered. |
| 733 | func (p *Parser) parseIdentifierExpression() (ast.Expression, error) { |
| 734 | // Ensure the current token is a valid identifier before proceeding. |
| 735 | if !p.currentTokenIs(token.IDENT) { |
| 736 | p.currentError(token.IDENT) |
| 737 | return nil, p.Error() |
| 738 | } |
| 739 | |
| 740 | // Create a new Identifier expression with the first token as the prefix. |
| 741 | ident := &ast.Identifier{Idents: []token.Token{p.currentToken}} |
| 742 | |
| 743 | // If the next token is a dot, consume it and continue parsing the next identifier. |
| 744 | for p.peekTokenIs(token.DOT) { |
| 745 | p.next() // Consume the dot token |
| 746 | |
| 747 | // Check if the next token after the dot is a valid identifier |
| 748 | if !p.expectAndNext(token.IDENT) { |
| 749 | return nil, p.Error() |
| 750 | } |
| 751 | |
| 752 | ident.Idents = append(ident.Idents, p.currentToken) |
| 753 | } |
| 754 | |
| 755 | // Return the resulting Identifier expression. |
| 756 | return ident, nil |
| 757 | } |
| 758 | |
| 759 | // call_func(variable1, variable2) |
| 760 | func (p *Parser) parseCallExpression() (ast.Expression, error) { |
no test coverage detected