use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseArrayTypeExpression.
private ParseTree parseArrayTypeExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree typeExpression = parseParenTypeExpression();
while (!peekImplicitSemiColon() && peek(TokenType.OPEN_SQUARE)) {
eat(TokenType.OPEN_SQUARE);
eat(TokenType.CLOSE_SQUARE);
typeExpression = new ArrayTypeTree(getTreeLocation(start), typeExpression);
}
return typeExpression;
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method maybeParseGenericTypes.
private GenericTypeListTree maybeParseGenericTypes() {
if (!peek(TokenType.OPEN_ANGLE)) {
return null;
}
SourcePosition start = getTreeStartLocation();
eat(TokenType.OPEN_ANGLE);
scanner.incTypeParameterLevel();
LinkedHashMap<IdentifierToken, ParseTree> types = new LinkedHashMap<>();
do {
IdentifierToken name = eatId();
ParseTree bound = null;
if (peek(TokenType.EXTENDS)) {
eat(TokenType.EXTENDS);
bound = parseType();
}
types.put(name, bound);
if (peek(TokenType.COMMA)) {
eat(TokenType.COMMA);
}
} while (peekId());
eat(TokenType.CLOSE_ANGLE);
scanner.decTypeParameterLevel();
return new GenericTypeListTree(getTreeLocation(start), types);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseIndexSignature.
private IndexSignatureTree parseIndexSignature() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.OPEN_SQUARE);
IdentifierToken name = eatIdOrKeywordAsId();
eat(TokenType.COLON);
// must be 'string' or 'number'
ParseTree indexType = parseTypeName();
eat(TokenType.CLOSE_SQUARE);
eat(TokenType.COLON);
ParseTree declaredType = parseType();
ParseTree nameTree = new MemberVariableTree(getTreeLocation(start), name, false, false, null, indexType);
return new IndexSignatureTree(getTreeLocation(start), nameTree, declaredType);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseCallSignature.
private CallSignatureTree parseCallSignature(boolean isNew) {
SourcePosition start = getTreeStartLocation();
if (isNew) {
eat(TokenType.NEW);
}
GenericTypeListTree generics = maybeParseGenericTypes();
FormalParameterListTree params = parseFormalParameterList(ParamContext.SIGNATURE);
ParseTree returnType = maybeParseColonType();
return new CallSignatureTree(getTreeLocation(start), isNew, generics, params, returnType);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseFormalParameterList.
private FormalParameterListTree parseFormalParameterList(ParamContext context) {
SourcePosition listStart = getTreeStartLocation();
eat(TokenType.OPEN_PAREN);
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
while (peekParameter(context)) {
result.add(parseParameter(context));
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 formal parameter list");
}
}
}
}
eat(TokenType.CLOSE_PAREN);
return new FormalParameterListTree(getTreeLocation(listStart), result.build());
}
Aggregations