use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseFormalParameterList.
private FormalParameterListTree parseFormalParameterList() {
SourcePosition listStart = getTreeStartLocation();
eat(TokenType.OPEN_PAREN);
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
boolean trailingComma = false;
ImmutableList.Builder<SourcePosition> commaPositions = ImmutableList.builder();
while (peekParameter()) {
result.add(parseParameter());
if (!peek(TokenType.CLOSE_PAREN)) {
Token comma = eat(TokenType.COMMA);
if (comma != null) {
commaPositions.add(comma.getStart());
} else {
// semi-arbitrary comma position in case the code is syntactially invalid & missing one
commaPositions.add(getTreeEndLocation());
}
if (peek(TokenType.CLOSE_PAREN)) {
recordFeatureUsed(Feature.TRAILING_COMMA_IN_PARAM_LIST);
if (!config.atLeast8) {
reportError(comma, "Invalid trailing comma in formal parameter list");
}
trailingComma = true;
}
}
}
eat(TokenType.CLOSE_PAREN);
return new FormalParameterListTree(getTreeLocation(listStart), result.build(), trailingComma, commaPositions.build());
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseReturnStatement.
// 12.9 The return Statement
private ParseTree parseReturnStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.RETURN);
ParseTree expression = null;
if (!peekImplicitSemiColon()) {
expression = parseExpression();
}
eatPossiblyImplicitSemiColon();
return new ReturnStatementTree(getTreeLocation(start), expression);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseExponentiationExpression.
private ParseTree parseExponentiationExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseUnaryExpression();
if (peek(TokenType.STAR_STAR)) {
// -x**y is a syntax error
if (left.type == ParseTreeType.UNARY_EXPRESSION) {
reportError("Unary operator '%s' requires parentheses before '**'", left.asUnaryExpression().operator);
}
Token operator = nextToken();
ParseTree right = parseExponentiationExpression();
return new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
} else {
return left;
}
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Scanner method nextTemplateLiteralTokenShared.
private TemplateLiteralToken nextTemplateLiteralTokenShared(TokenType endType, TokenType middleType) {
int beginIndex = index;
// Save the starting position to use with the multi-line safe version of getTokenRange().
SourcePosition startingPosition = getPosition(beginIndex);
SkipTemplateCharactersResult skipTemplateCharactersResult = skipTemplateCharacters();
if (isAtEnd()) {
reportError(getPosition(beginIndex), "Unterminated template literal");
}
String value = getTokenString(beginIndex);
switch(peekChar()) {
case '`':
nextChar();
return new TemplateLiteralToken(endType, value, skipTemplateCharactersResult.getErrorMessage(), skipTemplateCharactersResult.getPosition(), getTokenRange(startingPosition));
case '$':
// $
nextChar();
// {
nextChar();
return new TemplateLiteralToken(middleType, value, skipTemplateCharactersResult.getErrorMessage(), skipTemplateCharactersResult.getPosition(), getTokenRange(beginIndex - 1));
default:
// Should have reported error already
return new TemplateLiteralToken(endType, value, skipTemplateCharactersResult.getErrorMessage(), skipTemplateCharactersResult.getPosition(), getTokenRange(beginIndex - 1));
}
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parsePropertyAssignmentGenerator.
private ParseTree parsePropertyAssignmentGenerator() {
TokenType type = peekType(1);
if (type == TokenType.STRING || type == TokenType.NUMBER || type == TokenType.IDENTIFIER || Keywords.isKeyword(type)) {
// parseMethodDeclaration will consume the '*'.
return parseMethodDeclaration();
} else {
SourcePosition start = getTreeStartLocation();
eat(TokenType.STAR);
ParseTree name = parseComputedPropertyName();
FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.EXPRESSION);
parseFunctionTail(builder, FunctionFlavor.GENERATOR);
ParseTree value = builder.build(getTreeLocation(start));
return new ComputedPropertyMethodTree(getTreeLocation(start), name, value);
}
}
Aggregations