use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseTryStatement.
// 12.14 Try Statement
private ParseTree parseTryStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.TRY);
ParseTree body = parseBlock();
ParseTree catchBlock = null;
if (peek(TokenType.CATCH)) {
catchBlock = parseCatch();
}
ParseTree finallyBlock = null;
if (peek(TokenType.FINALLY)) {
finallyBlock = parseFinallyBlock();
}
if (catchBlock == null && finallyBlock == null) {
reportError("'catch' or 'finally' expected.");
}
return new TryStatementTree(getTreeLocation(start), body, catchBlock, finallyBlock);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseObjectPattern.
// Pattern ::= "{" (Field ("," Field)* ","?)? "}" | ...
private ParseTree parseObjectPattern(PatternKind kind) {
SourcePosition start = getTreeStartLocation();
ImmutableList.Builder<ParseTree> fields = ImmutableList.builder();
eat(TokenType.OPEN_CURLY);
while (peekObjectPatternField()) {
fields.add(parseObjectPatternField(kind));
if (peek(TokenType.COMMA)) {
// Consume the comma separator
eat(TokenType.COMMA);
} else {
// Otherwise we must be done
break;
}
}
if (peek(TokenType.ELLIPSIS)) {
recordFeatureUsed(Feature.OBJECT_PATTERN_REST);
SourcePosition restStart = getTreeStartLocation();
eat(TokenType.ELLIPSIS);
ParseTree patternAssignmentTarget = parseRestAssignmentTarget(kind);
fields.add(new ObjectRestTree(getTreeLocation(restStart), patternAssignmentTarget));
}
eat(TokenType.CLOSE_CURLY);
return new ObjectPatternTree(getTreeLocation(start), fields.build());
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseComprehensionFor.
private ParseTree parseComprehensionFor() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.FOR);
eat(TokenType.OPEN_PAREN);
ParseTree initializer;
if (peekId()) {
initializer = parseIdentifierExpression();
} else {
initializer = parsePattern(PatternKind.ANY);
}
eatPredefinedString(PredefinedName.OF);
ParseTree collection = parseAssignmentExpression();
eat(TokenType.CLOSE_PAREN);
return new ComprehensionForTree(getTreeLocation(start), initializer, collection);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseIfStatement.
// 12.5 If Statement
private IfStatementTree parseIfStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.IF);
eat(TokenType.OPEN_PAREN);
ParseTree condition = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree ifClause = parseStatement();
ParseTree elseClause = null;
if (peek(TokenType.ELSE)) {
eat(TokenType.ELSE);
elseClause = parseStatement();
}
return new IfStatementTree(getTreeLocation(start), condition, ifClause, elseClause);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseAssignment.
private ParseTree parseAssignment(Expression expressionIn) {
if (peek(TokenType.YIELD) && inGeneratorContext()) {
return parseYield(expressionIn);
}
SourcePosition start = getTreeStartLocation();
ParseTree left = parseConditional(expressionIn);
if (isStartOfAsyncArrowFunction(left)) {
// re-evaluate as an async arrow function.
resetScanner(left);
return parseAsyncArrowFunction(expressionIn);
}
if (peek(TokenType.ARROW)) {
return completeAssignmentExpressionParseAtArrow(left, expressionIn);
}
if (peekAssignmentOperator()) {
left = transformLeftHandSideExpression(left);
if (!left.isValidAssignmentTarget()) {
reportError("invalid assignment target");
return new MissingPrimaryExpressionTree(getTreeLocation(getTreeStartLocation()));
}
Token operator = nextToken();
ParseTree right = parseAssignment(expressionIn);
return new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
}
Aggregations