Search in sources :

Example 46 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 47 with SourcePosition

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

the class Parser method parseInterfaceDeclaration.

private ParseTree parseInterfaceDeclaration() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.INTERFACE);
    IdentifierToken name = eatId();
    GenericTypeListTree generics = maybeParseGenericTypes();
    ImmutableList.Builder<ParseTree> superTypes = ImmutableList.builder();
    if (peek(TokenType.EXTENDS)) {
        eat(TokenType.EXTENDS);
        ParseTree type = parseType();
        superTypes.add(type);
        while (peek(TokenType.COMMA)) {
            eat(TokenType.COMMA);
            type = parseType();
            if (type != null) {
                superTypes.add(type);
            }
        }
    }
    eat(TokenType.OPEN_CURLY);
    ImmutableList<ParseTree> elements = parseInterfaceElements();
    eat(TokenType.CLOSE_CURLY);
    return new InterfaceDeclarationTree(getTreeLocation(start), name, generics, superTypes.build(), elements);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) GenericTypeListTree(com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree) InterfaceDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.InterfaceDeclarationTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 48 with SourcePosition

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

the class Parser method parseTypeName.

private TypeNameTree parseTypeName() {
    SourcePosition start = getTreeStartLocation();
    // for 'void'.
    IdentifierToken token = eatIdOrKeywordAsId();
    return new TypeNameTree(getTreeLocation(start), buildIdentifierPath(token));
}
Also used : TypeNameTree(com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

Example 49 with SourcePosition

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

the class Parser method parseNamespaceDeclaration.

private NamespaceDeclarationTree parseNamespaceDeclaration(boolean isAmbient) {
    SourcePosition start = getTreeStartLocation();
    if (eatOpt(TokenType.MODULE) == null) {
        // Accept "module" or "namespace"
        eat(TokenType.NAMESPACE);
    }
    NamespaceNameTree name = parseNamespaceName();
    eat(TokenType.OPEN_CURLY);
    ImmutableList<ParseTree> elements = isAmbient ? parseAmbientNamespaceElements() : parseNamespaceElements();
    eat(TokenType.CLOSE_CURLY);
    return new NamespaceDeclarationTree(getTreeLocation(start), name, elements);
}
Also used : NamespaceNameTree(com.google.javascript.jscomp.parsing.parser.trees.NamespaceNameTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) NamespaceDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.NamespaceDeclarationTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 50 with SourcePosition

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

the class Parser method parseTypeQuery.

private ParseTree parseTypeQuery() {
    SourcePosition start = getTreeStartLocation();
    if (peek(TokenType.TYPEOF)) {
        eat(TokenType.TYPEOF);
        IdentifierToken token = eatId();
        ImmutableList.Builder<String> identifiers = ImmutableList.builder();
        if (token != null) {
            identifiers.add(token.value);
        }
        while (peek(TokenType.PERIOD)) {
            // TypeQueryExpression . IdentifierName
            eat(TokenType.PERIOD);
            token = eatId();
            if (token == null) {
                break;
            }
            identifiers.add(token.value);
        }
        return new TypeQueryTree(getTreeLocation(start), identifiers.build());
    } else {
        return parseTypeReference();
    }
}
Also used : TypeQueryTree(com.google.javascript.jscomp.parsing.parser.trees.TypeQueryTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) FormatString(com.google.errorprone.annotations.FormatString)

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