Search in sources :

Example 41 with SourcePosition

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

the class Scanner method scanStringLiteral.

private Token scanStringLiteral(int beginIndex, char terminator) {
    // String literals might span multiple lines.
    SourcePosition startingPosition = getPosition(beginIndex);
    boolean hasUnescapedUnicodeLineOrParagraphSeparator = false;
    while (peekStringLiteralChar(terminator)) {
        char c = peekChar();
        hasUnescapedUnicodeLineOrParagraphSeparator = hasUnescapedUnicodeLineOrParagraphSeparator || c == '\u2028' || c == '\u2029';
        if (!skipStringLiteralChar()) {
            return new StringLiteralToken(getTokenString(beginIndex), getTokenRange(startingPosition), hasUnescapedUnicodeLineOrParagraphSeparator);
        }
    }
    if (peekChar() != terminator) {
        reportError(getPosition(beginIndex), "Unterminated string literal");
    } else {
        nextChar();
    }
    return new StringLiteralToken(getTokenString(beginIndex), getTokenRange(startingPosition), hasUnescapedUnicodeLineOrParagraphSeparator);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

Example 42 with SourcePosition

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

the class Parser method parseCatch.

private CatchTree parseCatch() {
    SourcePosition start = getTreeStartLocation();
    CatchTree catchBlock;
    eat(TokenType.CATCH);
    ParseTree exception = new EmptyStatementTree(new SourceRange(getTreeEndLocation(), getTreeStartLocation()));
    if (peekToken().type == TokenType.OPEN_PAREN) {
        eat(TokenType.OPEN_PAREN);
        if (peekPatternStart()) {
            exception = parsePattern(PatternKind.INITIALIZER);
        } else {
            exception = parseIdentifierExpression();
        }
        eat(TokenType.CLOSE_PAREN);
    } else {
        recordFeatureUsed(Feature.OPTIONAL_CATCH_BINDING);
    }
    BlockTree catchBody = parseBlock();
    catchBlock = new CatchTree(getTreeLocation(start), exception, catchBody);
    return catchBlock;
}
Also used : EmptyStatementTree(com.google.javascript.jscomp.parsing.parser.trees.EmptyStatementTree) CatchTree(com.google.javascript.jscomp.parsing.parser.trees.CatchTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) BlockTree(com.google.javascript.jscomp.parsing.parser.trees.BlockTree) SourceRange(com.google.javascript.jscomp.parsing.parser.util.SourceRange) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 43 with SourcePosition

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

the class Parser method parseBitwiseAND.

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

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

the class Parser method parseMultiplicativeExpression.

// 11.5 Multiplicative Expression
private ParseTree parseMultiplicativeExpression() {
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseExponentiationExpression();
    while (peekMultiplicativeOperator()) {
        Token operator = nextToken();
        ParseTree right = parseExponentiationExpression();
        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 45 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)

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