Search in sources :

Example 16 with ParseTree

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

the class Parser method parseComprehensionIf.

private ParseTree parseComprehensionIf() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.IF);
    eat(TokenType.OPEN_PAREN);
    ParseTree initializer = parseAssignmentExpression();
    eat(TokenType.CLOSE_PAREN);
    return new ComprehensionIfTree(getTreeLocation(start), initializer);
}
Also used : ComprehensionIfTree(com.google.javascript.jscomp.parsing.parser.trees.ComprehensionIfTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 17 with ParseTree

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

the class Parser method parseProgram.

// 14 Program
public ProgramTree parseProgram() {
    try {
        SourcePosition start = getTreeStartLocation();
        ImmutableList<ParseTree> sourceElements = parseGlobalSourceElements();
        eat(TokenType.END_OF_FILE);
        return new ProgramTree(getTreeLocation(start), sourceElements, commentRecorder.getComments());
    } catch (Error e) {
        // StackOverflowError is not emulated on the Web.
        if (e.toString().contains("java.lang.StackOverflowError")) {
            reportError("Too deep recursion while parsing");
            return null;
        }
        throw e;
    }
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ProgramTree(com.google.javascript.jscomp.parsing.parser.trees.ProgramTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 18 with ParseTree

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

the class Parser method parseWithStatement.

// 12.10 The with Statement
private ParseTree parseWithStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.WITH);
    eat(TokenType.OPEN_PAREN);
    ParseTree expression = parseExpression();
    eat(TokenType.CLOSE_PAREN);
    ParseTree body = parseStatement();
    return new WithStatementTree(getTreeLocation(start), expression, body);
}
Also used : WithStatementTree(com.google.javascript.jscomp.parsing.parser.trees.WithStatementTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 19 with ParseTree

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

the class Parser method parseBitwiseOR.

// 11.10 Bitwise OR
private ParseTree parseBitwiseOR(Expression expressionIn) {
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseBitwiseXOR(expressionIn);
    while (peek(TokenType.BAR)) {
        Token operator = eat(TokenType.BAR);
        ParseTree right = parseBitwiseXOR(expressionIn);
        left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
    }
    return left;
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BinaryOperatorTree(com.google.javascript.jscomp.parsing.parser.trees.BinaryOperatorTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 20 with ParseTree

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

the class Parser method transformToArrowFormalParameters.

private FormalParameterListTree transformToArrowFormalParameters(ParseTree leftOfArrow) {
    FormalParameterListTree arrowParameterList;
    switch(leftOfArrow.type) {
        case FORMAL_PARAMETER_LIST:
            arrowParameterList = leftOfArrow.asFormalParameterList();
            break;
        case IDENTIFIER_EXPRESSION:
            // e.g. x => x + 1
            arrowParameterList = new FormalParameterListTree(leftOfArrow.location, ImmutableList.<ParseTree>of(leftOfArrow), /* hasTrailingComma= */
            false, ImmutableList.<SourcePosition>of());
            break;
        case ARGUMENT_LIST:
        case PAREN_EXPRESSION:
            // e.g. (x) => x + 1
            resetScanner(leftOfArrow);
            // If we fail to parse as an ArrowFunction parameter list then
            // parseFormalParameterList will take care of reporting errors.
            arrowParameterList = parseFormalParameterList();
            break;
        default:
            reportError(leftOfArrow, "invalid arrow function parameters");
            arrowParameterList = newEmptyFormalParameterList(leftOfArrow.location);
    }
    return arrowParameterList;
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) FormalParameterListTree(com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree) 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