Search in sources :

Example 1 with ComprehensionTree

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

the class Parser method parseComprehension.

private ParseTree parseComprehension(ComprehensionTree.ComprehensionType type, TokenType startToken, TokenType endToken) {
    SourcePosition start = getTreeStartLocation();
    eat(startToken);
    ImmutableList.Builder<ParseTree> children = ImmutableList.builder();
    while (peek(TokenType.FOR) || peek(TokenType.IF)) {
        if (peek(TokenType.FOR)) {
            children.add(parseComprehensionFor());
        } else {
            children.add(parseComprehensionIf());
        }
    }
    ParseTree tailExpression = parseAssignmentExpression();
    eat(endToken);
    return new ComprehensionTree(getTreeLocation(start), type, children.build(), tailExpression);
}
Also used : ComprehensionTree(com.google.javascript.jscomp.parsing.parser.trees.ComprehensionTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ComprehensionTree (com.google.javascript.jscomp.parsing.parser.trees.ComprehensionTree)1 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)1 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)1