Search in sources :

Example 71 with ParseTree

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

the class Parser method parseIterSpread.

private IterSpreadTree parseIterSpread() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.ELLIPSIS);
    ParseTree operand = parseAssignmentExpression();
    return new IterSpreadTree(getTreeLocation(start), operand);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) IterSpreadTree(com.google.javascript.jscomp.parsing.parser.trees.IterSpreadTree)

Example 72 with ParseTree

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

the class Parser method parseFunctionBody.

private BlockTree parseFunctionBody() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.OPEN_CURLY);
    ImmutableList<ParseTree> result = parseSourceElementList();
    eat(TokenType.CLOSE_CURLY);
    return new BlockTree(getTreeLocation(start), result);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 73 with ParseTree

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

the class Parser method parseBlock.

// 12.1 Block
private BlockTree parseBlock() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.OPEN_CURLY);
    // Spec says Statement list. However functions are also embedded in the wild.
    ImmutableList<ParseTree> result = parseSourceElementList();
    eat(TokenType.CLOSE_CURLY);
    return new BlockTree(getTreeLocation(start), result);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 74 with ParseTree

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

the class Parser method parseArrayLiteral.

// 11.1.4 Array Literal Expression
private ParseTree parseArrayLiteral() {
    // ArrayLiteral :
    // [ Elisionopt ]
    // [ ElementList ]
    // [ ElementList , Elisionopt ]
    // 
    // ElementList :
    // Elisionopt AssignmentOrSpreadExpression
    // ElementList , Elisionopt AssignmentOrSpreadExpression
    // 
    // Elision :
    // ,
    // Elision ,
    SourcePosition start = getTreeStartLocation();
    ImmutableList.Builder<ParseTree> elements = ImmutableList.builder();
    eat(TokenType.OPEN_SQUARE);
    Token trailingCommaToken = null;
    while (peek(TokenType.COMMA) || peek(TokenType.ELLIPSIS) || peekAssignmentExpression()) {
        trailingCommaToken = null;
        if (peek(TokenType.COMMA)) {
            SourcePosition commaStart = getTreeStartLocation();
            trailingCommaToken = eat(TokenType.COMMA);
            // Consider the empty element to start & end immediately before the comma token.
            elements.add(new NullTree(new SourceRange(commaStart, commaStart)));
        } else {
            if (peek(TokenType.ELLIPSIS)) {
                recordFeatureUsed(Feature.SPREAD_EXPRESSIONS);
                elements.add(parseIterSpread());
            } else {
                elements.add(parseAssignmentExpression());
            }
            if (!peek(TokenType.CLOSE_SQUARE)) {
                trailingCommaToken = eat(TokenType.COMMA);
            }
        }
    }
    eat(TokenType.CLOSE_SQUARE);
    maybeReportTrailingComma(trailingCommaToken);
    return new ArrayLiteralExpressionTree(getTreeLocation(start), elements.build(), trailingCommaToken != null);
}
Also used : ArrayLiteralExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.ArrayLiteralExpressionTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) 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)

Example 75 with ParseTree

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

the class Parser method parseTryStatement.

// 12.14 Try Statement
private ParseTree parseTryStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.TRY);
    ParseTree body = parseBlock();
    ParseTree catchBlock = null;
    if (peek(TokenType.CATCH)) {
        catchBlock = parseCatch();
    }
    ParseTree finallyBlock = null;
    if (peek(TokenType.FINALLY)) {
        finallyBlock = parseFinallyBlock();
    }
    if (catchBlock == null && finallyBlock == null) {
        reportError("'catch' or 'finally' expected.");
    }
    return new TryStatementTree(getTreeLocation(start), body, catchBlock, finallyBlock);
}
Also used : TryStatementTree(com.google.javascript.jscomp.parsing.parser.trees.TryStatementTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Aggregations

ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)100 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)81 ImmutableList (com.google.common.collect.ImmutableList)15 BinaryOperatorTree (com.google.javascript.jscomp.parsing.parser.trees.BinaryOperatorTree)14 FormalParameterListTree (com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree)9 FunctionDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree)6 BlockTree (com.google.javascript.jscomp.parsing.parser.trees.BlockTree)5 DefaultParameterTree (com.google.javascript.jscomp.parsing.parser.trees.DefaultParameterTree)5 SourceRange (com.google.javascript.jscomp.parsing.parser.util.SourceRange)5 ArgumentListTree (com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree)4 ComputedPropertyMethodTree (com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyMethodTree)4 OptionalMemberExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptionalMemberExpressionTree)4 OptionalMemberLookupExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptionalMemberLookupExpressionTree)4 ComputedPropertyMemberVariableTree (com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyMemberVariableTree)3 GenericTypeListTree (com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree)3 IdentifierExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree)3 NullTree (com.google.javascript.jscomp.parsing.parser.trees.NullTree)3 OptChainCallExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptChainCallExpressionTree)3 CommaExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.CommaExpressionTree)2 DoWhileStatementTree (com.google.javascript.jscomp.parsing.parser.trees.DoWhileStatementTree)2