Search in sources :

Example 1 with SourcePosition

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

the class Parser method parseThrowStatement.

// 12.13 Throw Statement
private ParseTree parseThrowStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.THROW);
    ParseTree value = null;
    if (peekImplicitSemiColon()) {
        reportError("semicolon/newline not allowed after 'throw'");
    } else {
        value = parseExpression();
    }
    eatPossibleImplicitSemiColon();
    return new ThrowStatementTree(getTreeLocation(start), value);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ThrowStatementTree(com.google.javascript.jscomp.parsing.parser.trees.ThrowStatementTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 2 with SourcePosition

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

the class Parser method parseMissingPrimaryExpression.

private ParseTree parseMissingPrimaryExpression() {
    SourcePosition start = getTreeStartLocation();
    nextToken();
    reportError("primary expression expected");
    return new MissingPrimaryExpressionTree(getTreeLocation(start));
}
Also used : MissingPrimaryExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.MissingPrimaryExpressionTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

Example 3 with SourcePosition

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

the class Parser method parseSpreadExpression.

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

Example 4 with SourcePosition

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

the class Parser method parseCaseClauses.

private ImmutableList<ParseTree> parseCaseClauses() {
    boolean foundDefaultClause = false;
    ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
    while (true) {
        SourcePosition start = getTreeStartLocation();
        switch(peekType()) {
            case CASE:
                eat(TokenType.CASE);
                ParseTree expression = parseExpression();
                eat(TokenType.COLON);
                ImmutableList<ParseTree> statements = parseCaseStatementsOpt();
                result.add(new CaseClauseTree(getTreeLocation(start), expression, statements));
                break;
            case DEFAULT:
                if (foundDefaultClause) {
                    reportError("Switch statements may have at most one default clause");
                } else {
                    foundDefaultClause = true;
                }
                eat(TokenType.DEFAULT);
                eat(TokenType.COLON);
                result.add(new DefaultClauseTree(getTreeLocation(start), parseCaseStatementsOpt()));
                break;
            default:
                return result.build();
        }
    }
}
Also used : DefaultClauseTree(com.google.javascript.jscomp.parsing.parser.trees.DefaultClauseTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) CaseClauseTree(com.google.javascript.jscomp.parsing.parser.trees.CaseClauseTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 5 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();
    eat(TokenType.OPEN_PAREN);
    while (peekAssignmentOrSpread()) {
        arguments.add(parseAssignmentOrSpread());
        if (!peek(TokenType.CLOSE_PAREN)) {
            Token comma = eat(TokenType.COMMA);
            if (peek(TokenType.CLOSE_PAREN)) {
                features = features.with(Feature.TRAILING_COMMA_IN_PARAM_LIST);
                if (!config.atLeast8) {
                    reportError(comma, "Invalid trailing comma in arguments list");
                }
            }
        }
    }
    eat(TokenType.CLOSE_PAREN);
    return new ArgumentListTree(getTreeLocation(start), arguments.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)

Aggregations

SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)98 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)71 ImmutableList (com.google.common.collect.ImmutableList)15 BinaryOperatorTree (com.google.javascript.jscomp.parsing.parser.trees.BinaryOperatorTree)12 FunctionDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.FunctionDeclarationTree)6 FormalParameterListTree (com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree)5 BlockTree (com.google.javascript.jscomp.parsing.parser.trees.BlockTree)4 DefaultParameterTree (com.google.javascript.jscomp.parsing.parser.trees.DefaultParameterTree)4 GenericTypeListTree (com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree)4 IdentifierExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.IdentifierExpressionTree)4 ArrayLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.ArrayLiteralExpressionTree)3 ObjectLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.ObjectLiteralExpressionTree)3 TemplateLiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.TemplateLiteralExpressionTree)3 VariableDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.VariableDeclarationTree)3 ArgumentListTree (com.google.javascript.jscomp.parsing.parser.trees.ArgumentListTree)2 CommaExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.CommaExpressionTree)2 ComputedPropertyMemberVariableTree (com.google.javascript.jscomp.parsing.parser.trees.ComputedPropertyMemberVariableTree)2 DoWhileStatementTree (com.google.javascript.jscomp.parsing.parser.trees.DoWhileStatementTree)2 LiteralExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.LiteralExpressionTree)2 MemberExpressionTree (com.google.javascript.jscomp.parsing.parser.trees.MemberExpressionTree)2