use of com.google.javascript.jscomp.parsing.parser.trees.CommaExpressionTree in project closure-compiler by google.
the class Parser method parseCoverParenthesizedExpressionAndArrowParameterList.
// 12.2 Primary Expression
// CoverParenthesizedExpressionAndArrowParameterList ::=
// ( Expression )
// ( Expression, )
// ( )
// ( ... BindingIdentifier )
// ( Expression , ... BindingIdentifier )
private ParseTree parseCoverParenthesizedExpressionAndArrowParameterList() {
if (peekType(1) == TokenType.FOR) {
return parseGeneratorComprehension();
}
SourcePosition start = getTreeStartLocation();
eat(TokenType.OPEN_PAREN);
// Case ( )
if (peek(TokenType.CLOSE_PAREN)) {
eat(TokenType.CLOSE_PAREN);
if (peek(TokenType.ARROW)) {
return new FormalParameterListTree(getTreeLocation(start), ImmutableList.<ParseTree>of(), /* hasTrailingComma= */
false, ImmutableList.<SourcePosition>of());
} else {
reportError("invalid parenthesized expression");
return new MissingPrimaryExpressionTree(getTreeLocation(start));
}
}
// Case ( ... BindingIdentifier )
if (peek(TokenType.ELLIPSIS)) {
ImmutableList<ParseTree> params = ImmutableList.of(parseParameter());
eat(TokenType.CLOSE_PAREN);
if (peek(TokenType.ARROW)) {
return new FormalParameterListTree(getTreeLocation(start), params, /* hasTrailingComma= */
false, ImmutableList.<SourcePosition>of());
} else {
reportError("invalid parenthesized expression");
return new MissingPrimaryExpressionTree(getTreeLocation(start));
}
}
// For either of the three remaining cases:
// ( Expression )
// ( Expression, )
// ( Expression, ...BindingIdentifier )
// we can parse as an expression.
ParseTree result = parseExpression();
// case.
if (peek(TokenType.COMMA)) {
if (peek(1, TokenType.CLOSE_PAREN)) {
// Create the formal parameter list here so we can record
// the trailing comma
resetScanner(start);
// parseFormalParameterList will take care of reporting errors.
return parseFormalParameterList();
} else {
eat(TokenType.COMMA);
// Since we already parsed as an expression, we will guaranteed reparse this expression
// as an arrow function parameter list, but just leave it as a comma expression for now.
result = new CommaExpressionTree(getTreeLocation(start), ImmutableList.of(result, parseParameter()));
}
}
eat(TokenType.CLOSE_PAREN);
return new ParenExpressionTree(getTreeLocation(start), result);
}
use of com.google.javascript.jscomp.parsing.parser.trees.CommaExpressionTree in project closure-compiler by google.
the class Parser method parse.
private ParseTree parse(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree result = parseAssignment(expressionIn);
if (peek(TokenType.COMMA) && !peek(1, TokenType.ELLIPSIS) && !peek(1, TokenType.CLOSE_PAREN)) {
ImmutableList.Builder<ParseTree> exprs = ImmutableList.builder();
exprs.add(result);
while (peek(TokenType.COMMA) && !peek(1, TokenType.ELLIPSIS) && !peek(1, TokenType.CLOSE_PAREN)) {
eat(TokenType.COMMA);
exprs.add(parseAssignment(expressionIn));
}
return new CommaExpressionTree(getTreeLocation(start), exprs.build());
}
return result;
}
Aggregations