use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree 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.trees.ParseTree 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;
}
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseWithStatement.
// 12.10 The with Statement
private ParseTree parseWithStatement() {
SourcePosition start = getTreeStartLocation();
eat(TokenType.WITH);
eat(TokenType.OPEN_PAREN);
ParseTree expression = parseExpression();
eat(TokenType.CLOSE_PAREN);
ParseTree body = parseStatement();
return new WithStatementTree(getTreeLocation(start), expression, body);
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method parseBitwiseOR.
// 11.10 Bitwise OR
private ParseTree parseBitwiseOR(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseBitwiseXOR(expressionIn);
while (peek(TokenType.BAR)) {
Token operator = eat(TokenType.BAR);
ParseTree right = parseBitwiseXOR(expressionIn);
left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
}
return left;
}
use of com.google.javascript.jscomp.parsing.parser.trees.ParseTree in project closure-compiler by google.
the class Parser method transformToArrowFormalParameters.
private FormalParameterListTree transformToArrowFormalParameters(ParseTree leftOfArrow) {
FormalParameterListTree arrowParameterList;
switch(leftOfArrow.type) {
case FORMAL_PARAMETER_LIST:
arrowParameterList = leftOfArrow.asFormalParameterList();
break;
case IDENTIFIER_EXPRESSION:
// e.g. x => x + 1
arrowParameterList = new FormalParameterListTree(leftOfArrow.location, ImmutableList.<ParseTree>of(leftOfArrow), /* hasTrailingComma= */
false, ImmutableList.<SourcePosition>of());
break;
case ARGUMENT_LIST:
case PAREN_EXPRESSION:
// e.g. (x) => x + 1
resetScanner(leftOfArrow);
// If we fail to parse as an ArrowFunction parameter list then
// parseFormalParameterList will take care of reporting errors.
arrowParameterList = parseFormalParameterList();
break;
default:
reportError(leftOfArrow, "invalid arrow function parameters");
arrowParameterList = newEmptyFormalParameterList(leftOfArrow.location);
}
return arrowParameterList;
}
Aggregations