Search in sources :

Example 26 with SourcePosition

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

the class Parser method parseThisExpression.

private ThisExpressionTree parseThisExpression() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.THIS);
    return new ThisExpressionTree(getTreeLocation(start));
}
Also used : ThisExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.ThisExpressionTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

Example 27 with SourcePosition

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

the class Parser method parseIterRest.

private ParseTree parseIterRest(PatternKind patternKind) {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.ELLIPSIS);
    ParseTree patternAssignmentTarget = parseRestAssignmentTarget(patternKind);
    return new IterRestTree(getTreeLocation(start), patternAssignmentTarget);
}
Also used : IterRestTree(com.google.javascript.jscomp.parsing.parser.trees.IterRestTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 28 with SourcePosition

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

the class Parser method parseCoverParenthesizedExpressionAndArrowParameterList.

// 12.2 Primary Expression
// CoverParenthesizedExpressionAndArrowParameterList ::=
// ( Expression )
// ( Expression, )
// ( )
// ( ... BindingIdentifier )
// ( Expression , ... BindingIdentifier )
private ParseTree parseCoverParenthesizedExpressionAndArrowParameterList() {
    if (peekType(1) == TokenType.FOR) {
        return parseGeneratorComprehension();
    }
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.OPEN_PAREN);
    // Case ( )
    if (peek(TokenType.CLOSE_PAREN)) {
        eat(TokenType.CLOSE_PAREN);
        if (peek(TokenType.ARROW)) {
            return new FormalParameterListTree(getTreeLocation(start), ImmutableList.<ParseTree>of(), /* hasTrailingComma= */
            false, ImmutableList.<SourcePosition>of());
        } else {
            reportError("invalid parenthesized expression");
            return new MissingPrimaryExpressionTree(getTreeLocation(start));
        }
    }
    // Case ( ... BindingIdentifier )
    if (peek(TokenType.ELLIPSIS)) {
        ImmutableList<ParseTree> params = ImmutableList.of(parseParameter());
        eat(TokenType.CLOSE_PAREN);
        if (peek(TokenType.ARROW)) {
            return new FormalParameterListTree(getTreeLocation(start), params, /* hasTrailingComma= */
            false, ImmutableList.<SourcePosition>of());
        } else {
            reportError("invalid parenthesized expression");
            return new MissingPrimaryExpressionTree(getTreeLocation(start));
        }
    }
    // For either of the three remaining cases:
    // ( Expression )
    // ( Expression, )
    // ( Expression, ...BindingIdentifier )
    // we can parse as an expression.
    ParseTree result = parseExpression();
    // case.
    if (peek(TokenType.COMMA)) {
        if (peek(1, TokenType.CLOSE_PAREN)) {
            // Create the formal parameter list here so we can record
            // the trailing comma
            resetScanner(start);
            // parseFormalParameterList will take care of reporting errors.
            return parseFormalParameterList();
        } else {
            eat(TokenType.COMMA);
            // Since we already parsed as an expression, we will guaranteed reparse this expression
            // as an arrow function parameter list, but just leave it as a comma expression for now.
            result = new CommaExpressionTree(getTreeLocation(start), ImmutableList.of(result, parseParameter()));
        }
    }
    eat(TokenType.CLOSE_PAREN);
    return new ParenExpressionTree(getTreeLocation(start), result);
}
Also used : CommaExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.CommaExpressionTree) MissingPrimaryExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.MissingPrimaryExpressionTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ParenExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.ParenExpressionTree) FormalParameterListTree(com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 29 with SourcePosition

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

the class Parser method parseExpressionStatement.

// 12.4 Expression Statement
private ExpressionStatementTree parseExpressionStatement() {
    SourcePosition start = getTreeStartLocation();
    ParseTree expression = parseExpression();
    eatPossiblyImplicitSemiColon();
    return new ExpressionStatementTree(getTreeLocation(start), expression);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) ExpressionStatementTree(com.google.javascript.jscomp.parsing.parser.trees.ExpressionStatementTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 30 with SourcePosition

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

the class Parser method parseContinueStatement.

// 12.7 The continue Statement
private ParseTree parseContinueStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.CONTINUE);
    IdentifierToken name = null;
    if (!peekImplicitSemiColon()) {
        name = eatIdOpt();
    }
    eatPossiblyImplicitSemiColon();
    return new ContinueStatementTree(getTreeLocation(start), name);
}
Also used : ContinueStatementTree(com.google.javascript.jscomp.parsing.parser.trees.ContinueStatementTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

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