Search in sources :

Example 1 with ForStatementTree

use of com.google.javascript.jscomp.parsing.parser.trees.ForStatementTree in project closure-compiler by google.

the class Parser method parseForStatement.

// 12.6.3 The for Statement
private ParseTree parseForStatement(SourcePosition start, ParseTree initializer) {
    if (initializer == null) {
        initializer = new NullTree(new SourceRange(getTreeEndLocation(), getTreeStartLocation()));
    }
    eat(TokenType.SEMI_COLON);
    ParseTree condition;
    if (!peek(TokenType.SEMI_COLON)) {
        condition = parseExpression();
    } else {
        condition = new NullTree(new SourceRange(getTreeEndLocation(), getTreeStartLocation()));
    }
    eat(TokenType.SEMI_COLON);
    ParseTree increment;
    if (!peek(TokenType.CLOSE_PAREN)) {
        increment = parseExpression();
    } else {
        increment = new NullTree(new SourceRange(getTreeEndLocation(), getTreeStartLocation()));
    }
    eat(TokenType.CLOSE_PAREN);
    ParseTree body = parseStatement();
    return new ForStatementTree(getTreeLocation(start), initializer, condition, increment, body);
}
Also used : ForStatementTree(com.google.javascript.jscomp.parsing.parser.trees.ForStatementTree) NullTree(com.google.javascript.jscomp.parsing.parser.trees.NullTree) SourceRange(com.google.javascript.jscomp.parsing.parser.util.SourceRange) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Aggregations

ForStatementTree (com.google.javascript.jscomp.parsing.parser.trees.ForStatementTree)1 NullTree (com.google.javascript.jscomp.parsing.parser.trees.NullTree)1 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)1 SourceRange (com.google.javascript.jscomp.parsing.parser.util.SourceRange)1