use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseArguments.
private ArgumentListTree parseArguments() {
// ArgumentList :
// AssignmentOrSpreadExpression
// ArgumentList , AssignmentOrSpreadExpression
//
// AssignmentOrSpreadExpression :
// ... AssignmentExpression
// AssignmentExpression
SourcePosition start = getTreeStartLocation();
ImmutableList.Builder<ParseTree> arguments = ImmutableList.builder();
boolean trailingComma = false;
ImmutableList.Builder<SourcePosition> commaPositions = ImmutableList.builder();
eat(TokenType.OPEN_PAREN);
while (peekAssignmentOrSpread()) {
arguments.add(parseAssignmentOrSpread());
if (!peek(TokenType.CLOSE_PAREN)) {
Token comma = eat(TokenType.COMMA);
if (comma != null) {
commaPositions.add(comma.getStart());
}
if (peek(TokenType.CLOSE_PAREN)) {
recordFeatureUsed(Feature.TRAILING_COMMA_IN_PARAM_LIST);
if (!config.atLeast8) {
reportError(comma, "Invalid trailing comma in arguments list");
}
trailingComma = true;
}
}
}
eat(TokenType.CLOSE_PAREN);
return new ArgumentListTree(getTreeLocation(start), arguments.build(), trailingComma, commaPositions.build());
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseAwaitExpression.
private ParseTree parseAwaitExpression() {
SourcePosition start = getTreeStartLocation();
if (functionContextStack.isEmpty() || !functionContextStack.peekLast().isAsynchronous) {
reportError("'await' used in a non-async function context");
}
eatPredefinedString(AWAIT);
ParseTree expression = parseUnaryExpression();
return new AwaitExpressionTree(getTreeLocation(start), expression);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseLogicalAND.
// 11.11 Logical AND
private ParseTree parseLogicalAND(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseBitwiseOR(expressionIn);
while (peek(TokenType.AND)) {
Token operator = eat(TokenType.AND);
ParseTree right = parseBitwiseOR(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseComprehensionIf.
private ParseTree parseComprehensionIf() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.IF);
eat(TokenType.OPEN_PAREN);
ParseTree initializer = parseAssignmentExpression();
eat(TokenType.CLOSE_PAREN);
return new ComprehensionIfTree(getTreeLocation(start), initializer);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseProgram.
// 14 Program
public ProgramTree parseProgram() {
try {
SourcePosition start = getTreeStartLocation();
ImmutableList<ParseTree> sourceElements = parseGlobalSourceElements();
eat(TokenType.END_OF_FILE);
return new ProgramTree(getTreeLocation(start), sourceElements, commentRecorder.getComments());
} catch (Error e) {
// StackOverflowError is not emulated on the Web.
if (e.toString().contains("java.lang.StackOverflowError")) {
reportError("Too deep recursion while parsing");
return null;
}
throw e;
}
}
Aggregations