Search in sources :

Example 91 with SourcePosition

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

the class Parser method parseBitwiseXOR.

// 11.10 Bitwise XOR
private ParseTree parseBitwiseXOR(Expression expressionIn) {
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseBitwiseAND(expressionIn);
    while (peek(TokenType.CARET)) {
        Token operator = eat(TokenType.CARET);
        ParseTree right = parseBitwiseAND(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 92 with SourcePosition

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

the class Parser method parseNewDotSomething.

private ParseTree parseNewDotSomething() {
    // currently only "target" is valid after "new."
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.NEW);
    eat(TokenType.PERIOD);
    eatPredefinedString("target");
    return new NewTargetExpressionTree(getTreeLocation(start));
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) NewTargetExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.NewTargetExpressionTree)

Example 93 with SourcePosition

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

the class Parser method parseSwitchStatement.

// 12.11 The switch Statement
private ParseTree parseSwitchStatement() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.SWITCH);
    eat(TokenType.OPEN_PAREN);
    ParseTree expression = parseExpression();
    eat(TokenType.CLOSE_PAREN);
    eat(TokenType.OPEN_CURLY);
    ImmutableList<ParseTree> caseClauses = parseCaseClauses();
    eat(TokenType.CLOSE_CURLY);
    return new SwitchStatementTree(getTreeLocation(start), expression, caseClauses);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) SwitchStatementTree(com.google.javascript.jscomp.parsing.parser.trees.SwitchStatementTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 94 with SourcePosition

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

the class Parser method parseArrayPattern.

// Pattern ::= ... | "[" Element? ("," Element?)* "]"
private ParseTree parseArrayPattern(PatternKind kind) {
    SourcePosition start = getTreeStartLocation();
    ImmutableList.Builder<ParseTree> elements = ImmutableList.builder();
    eat(TokenType.OPEN_SQUARE);
    while (peek(TokenType.COMMA) || peekArrayPatternElement()) {
        if (peek(TokenType.COMMA)) {
            SourcePosition nullStart = getTreeStartLocation();
            eat(TokenType.COMMA);
            elements.add(new NullTree(getTreeLocation(nullStart)));
        } else {
            elements.add(parsePatternAssignmentTarget(kind));
            if (peek(TokenType.COMMA)) {
                // Consume the comma separator
                eat(TokenType.COMMA);
            } else {
                // Otherwise we must be done
                break;
            }
        }
    }
    if (peek(TokenType.ELLIPSIS)) {
        recordFeatureUsed(Feature.ARRAY_PATTERN_REST);
        elements.add(parseIterRest(kind));
    }
    if (eat(TokenType.CLOSE_SQUARE) == null) {
        // source has syntactic errors.
        return new MissingPrimaryExpressionTree(getTreeLocation(getTreeStartLocation()));
    }
    return new ArrayPatternTree(getTreeLocation(start), elements.build());
}
Also used : MissingPrimaryExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.MissingPrimaryExpressionTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) NullTree(com.google.javascript.jscomp.parsing.parser.trees.NullTree) ArrayPatternTree(com.google.javascript.jscomp.parsing.parser.trees.ArrayPatternTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 95 with SourcePosition

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

the class Parser method parseObjectLiteral.

// 11.1.4 Object Literal Expression
private ParseTree parseObjectLiteral() {
    SourcePosition start = getTreeStartLocation();
    ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
    eat(TokenType.OPEN_CURLY);
    Token commaToken = null;
    while (peek(TokenType.ELLIPSIS) || peekPropertyNameOrComputedProp(0) || peek(TokenType.STAR)) {
        result.add(parsePropertyAssignment());
        commaToken = eatOpt(TokenType.COMMA);
        if (commaToken == null) {
            break;
        }
    }
    eat(TokenType.CLOSE_CURLY);
    maybeReportTrailingComma(commaToken);
    return new ObjectLiteralExpressionTree(getTreeLocation(start), result.build(), commaToken != null);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ObjectLiteralExpressionTree(com.google.javascript.jscomp.parsing.parser.trees.ObjectLiteralExpressionTree) 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)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