use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Scanner method scanStringLiteral.
private Token scanStringLiteral(int beginIndex, char terminator) {
// String literals might span multiple lines.
SourcePosition startingPosition = getPosition(beginIndex);
boolean hasUnescapedUnicodeLineOrParagraphSeparator = false;
while (peekStringLiteralChar(terminator)) {
char c = peekChar();
hasUnescapedUnicodeLineOrParagraphSeparator = hasUnescapedUnicodeLineOrParagraphSeparator || c == '\u2028' || c == '\u2029';
if (!skipStringLiteralChar()) {
return new StringLiteralToken(getTokenString(beginIndex), getTokenRange(startingPosition), hasUnescapedUnicodeLineOrParagraphSeparator);
}
}
if (peekChar() != terminator) {
reportError(getPosition(beginIndex), "Unterminated string literal");
} else {
nextChar();
}
return new StringLiteralToken(getTokenString(beginIndex), getTokenRange(startingPosition), hasUnescapedUnicodeLineOrParagraphSeparator);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseCatch.
private CatchTree parseCatch() {
SourcePosition start = getTreeStartLocation();
CatchTree catchBlock;
eat(TokenType.CATCH);
ParseTree exception = new EmptyStatementTree(new SourceRange(getTreeEndLocation(), getTreeStartLocation()));
if (peekToken().type == TokenType.OPEN_PAREN) {
eat(TokenType.OPEN_PAREN);
if (peekPatternStart()) {
exception = parsePattern(PatternKind.INITIALIZER);
} else {
exception = parseIdentifierExpression();
}
eat(TokenType.CLOSE_PAREN);
} else {
recordFeatureUsed(Feature.OPTIONAL_CATCH_BINDING);
}
BlockTree catchBody = parseBlock();
catchBlock = new CatchTree(getTreeLocation(start), exception, catchBody);
return catchBlock;
}
use of com.google.javascript.jscomp.parsing.parser.util.SourcePosition in project closure-compiler by google.
the class Parser method parseBitwiseAND.
// 11.10 Bitwise AND
private ParseTree parseBitwiseAND(Expression expressionIn) {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseEquality(expressionIn);
while (peek(TokenType.AMPERSAND)) {
Token operator = eat(TokenType.AMPERSAND);
ParseTree right = parseEquality(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 parseMultiplicativeExpression.
// 11.5 Multiplicative Expression
private ParseTree parseMultiplicativeExpression() {
SourcePosition start = getTreeStartLocation();
ParseTree left = parseExponentiationExpression();
while (peekMultiplicativeOperator()) {
Token operator = nextToken();
ParseTree right = parseExponentiationExpression();
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 parseCaseClauses.
private ImmutableList<ParseTree> parseCaseClauses() {
boolean foundDefaultClause = false;
ImmutableList.Builder<ParseTree> result = ImmutableList.builder();
while (true) {
SourcePosition start = getTreeStartLocation();
switch(peekType()) {
case CASE:
eat(TokenType.CASE);
ParseTree expression = parseExpression();
eat(TokenType.COLON);
ImmutableList<ParseTree> statements = parseCaseStatementsOpt();
result.add(new CaseClauseTree(getTreeLocation(start), expression, statements));
break;
case DEFAULT:
if (foundDefaultClause) {
reportError("Switch statements may have at most one default clause");
} else {
foundDefaultClause = true;
}
eat(TokenType.DEFAULT);
eat(TokenType.COLON);
result.add(new DefaultClauseTree(getTreeLocation(start), parseCaseStatementsOpt()));
break;
default:
return result.build();
}
}
}
Aggregations