Search in sources :

Example 16 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.

the class Parser method parseArguments.

private ArgumentListTree parseArguments() {
    // ArgumentList :
    // AssignmentOrSpreadExpression
    // ArgumentList , AssignmentOrSpreadExpression
    // 
    // AssignmentOrSpreadExpression :
    // ... AssignmentExpression
    // AssignmentExpression
    SourcePosition start = getTreeStartLocation();
    ImmutableList.Builder<ParseTree> arguments = ImmutableList.builder();
    boolean trailingComma = false;
    ImmutableList.Builder<SourcePosition> commaPositions = ImmutableList.builder();
    eat(TokenType.OPEN_PAREN);
    while (peekAssignmentOrSpread()) {
        arguments.add(parseAssignmentOrSpread());
        if (!peek(TokenType.CLOSE_PAREN)) {
            Token comma = eat(TokenType.COMMA);
            if (comma != null) {
                commaPositions.add(comma.getStart());
            }
            if (peek(TokenType.CLOSE_PAREN)) {
                recordFeatureUsed(Feature.TRAILING_COMMA_IN_PARAM_LIST);
                if (!config.atLeast8) {
                    reportError(comma, "Invalid trailing comma in arguments list");
                }
                trailingComma = true;
            }
        }
    }
    eat(TokenType.CLOSE_PAREN);
    return new ArgumentListTree(getTreeLocation(start), arguments.build(), trailingComma, commaPositions.build());
}
Also used : ArgumentListTree(com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 17 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.

the class Parser method parseAwaitExpression.

private ParseTree parseAwaitExpression() {
    SourcePosition start = getTreeStartLocation();
    if (functionContextStack.isEmpty() || !functionContextStack.peekLast().isAsynchronous) {
        reportError("'await' used in a non-async function context");
    }
    eatPredefinedString(AWAIT);
    ParseTree expression = parseUnaryExpression();
    return new AwaitExpressionTree(getTreeLocation(start), expression);
}
Also used : AwaitExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.AwaitExpressionTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 18 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.

the class Parser method parseLogicalAND.

// 11.11 Logical AND
private ParseTree parseLogicalAND(Expression expressionIn) {
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseBitwiseOR(expressionIn);
    while (peek(TokenType.AND)) {
        Token operator = eat(TokenType.AND);
        ParseTree right = parseBitwiseOR(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 19 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition 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 20 with SourcePosition

use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition 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)

Aggregations

SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)112 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)81 ImmutableList (com.google.common.collect.ImmutableList)15 BinaryOperatorTree (com.google.javascript.jscomp.parsing.parser.trees.BinaryOperatorTree)13 FormalParameterListTree (com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree)7 FunctionDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree)6 DefaultParameterTree (com.google.javascript.jscomp.parsing.parser.trees.DefaultParameterTree)5 ArgumentListTree (com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree)4 BlockTree (com.google.javascript.jscomp.parsing.parser.trees.BlockTree)4 IdentifierExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree)4 MissingPrimaryExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.MissingPrimaryExpressionTree)4 OptionalMemberExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptionalMemberExpressionTree)4 OptionalMemberLookupExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptionalMemberLookupExpressionTree)4 ArrayLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.ArrayLiteralExpressionTree)3 GenericTypeListTree (com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree)3 ObjectLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.ObjectLiteralExpressionTree)3 OptChainCallExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.OptChainCallExpressionTree)3 TemplateLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.TemplateLiteralExpressionTree)3 VariableDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.VariableDeclarationTree)3 FormatString (com.google.errorprone.annotations.FormatString)2