()
| 1633 | } |
| 1634 | |
| 1635 | public Statement forStatement() { |
| 1636 | Token position = consume(FOR); |
| 1637 | consume(LEFT_PAREN); |
| 1638 | if (la() == VAR) { |
| 1639 | consume(VAR); |
| 1640 | List<VariableDeclaration> varDeclList = variableDeclarationList(true); |
| 1641 | if (la() == IN) { |
| 1642 | if (varDeclList.size() != 1) { |
| 1643 | throw new SyntaxError(varDeclList.get(1).getPosition(), "only one variable declaration is allowed"); |
| 1644 | } |
| 1645 | // for ( var-decl in ... ) |
| 1646 | consume(IN); |
| 1647 | Expression rhs = expression(); |
| 1648 | consume(RIGHT_PAREN); |
| 1649 | Statement body = statement(); |
| 1650 | |
| 1651 | return factory.forInStatement(position, varDeclList.get(0), rhs, body); |
| 1652 | } else if (la() == OF) { |
| 1653 | if (varDeclList.size() != 1) { |
| 1654 | throw new SyntaxError(varDeclList.get(1).getPosition(), "only one variable declaration is allowed"); |
| 1655 | } |
| 1656 | // for ( var-decl of ... ) |
| 1657 | consume(OF); |
| 1658 | Expression rhs = expression(); |
| 1659 | consume(RIGHT_PAREN); |
| 1660 | Statement body = statement(); |
| 1661 | |
| 1662 | return factory.forOfStatement(position, varDeclList.get(0), rhs, body); |
| 1663 | } else { |
| 1664 | // for ( var-decl-list ; ... ; ... ) |
| 1665 | consume(SEMICOLON); |
| 1666 | Expression middle = null; |
| 1667 | Expression rhs = null; |
| 1668 | if (la() != SEMICOLON) { |
| 1669 | middle = expression(); |
| 1670 | } |
| 1671 | consume(SEMICOLON); |
| 1672 | if (la() != RIGHT_PAREN) { |
| 1673 | rhs = expression(); |
| 1674 | } |
| 1675 | consume(RIGHT_PAREN); |
| 1676 | Statement body = statement(); |
| 1677 | return factory.forStatement(position, varDeclList, middle, rhs, body); |
| 1678 | } |
| 1679 | } else { |
| 1680 | Expression initializer = null; |
| 1681 | if (la() == SEMICOLON) { |
| 1682 | // for ( ;... ; ... ) |
| 1683 | // no initializer |
| 1684 | } else { |
| 1685 | initializer = expressionNoIn(); |
| 1686 | } |
| 1687 | |
| 1688 | if (la() == IN) { |
| 1689 | consume(IN); |
| 1690 | // for ( expr in expr ) |
| 1691 | Expression rhs = expression(); |
| 1692 | consume(RIGHT_PAREN); |
no test coverage detected