use of com.google.javascript.jscomp.parsing.parser.util.SourceRange in project closure-compiler by google.
the class Scanner method skipSingleLineComment.
private void skipSingleLineComment(Comment.Type type) {
int startOffset = index;
while (!isAtEnd() && !isLineTerminator(peekChar())) {
nextChar();
}
SourceRange range = lineNumberScanner.getSourceRange(startOffset, index);
String value = this.contents.substring(startOffset, index);
recordComment(type, range, value);
}
use of com.google.javascript.jscomp.parsing.parser.util.SourceRange in project closure-compiler by google.
the class Scanner method skipMultiLineComment.
private void skipMultiLineComment() {
int startOffset = index;
// '/'
nextChar();
// '*'
nextChar();
while (!isAtEnd() && (peekChar() != '*' || peekChar(1) != '/')) {
nextChar();
}
if (!isAtEnd()) {
nextChar();
nextChar();
Comment.Type type = Comment.Type.BLOCK;
if (index - startOffset > 4) {
if (this.contents.charAt(startOffset + 2) == '*') {
type = Comment.Type.JSDOC;
} else if (this.contents.charAt(startOffset + 2) == '!') {
type = Comment.Type.IMPORTANT;
}
}
SourceRange range = lineNumberScanner.getSourceRange(startOffset, index);
String value = this.contents.substring(startOffset, index);
recordComment(type, range, value);
} else {
reportError("unterminated comment");
}
}
use of com.google.javascript.jscomp.parsing.parser.util.SourceRange 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.SourceRange in project closure-compiler by google.
the class IRFactory method normalizeNumber.
double normalizeNumber(LiteralToken token) {
String value = token.value;
if (value.contains("_")) {
value = removeNumericSeparators(value, token);
}
SourceRange location = token.location;
int length = value.length();
checkState(length > 0);
checkState(value.charAt(0) != '-' && value.charAt(0) != '+');
if (value.charAt(0) == '.') {
return Double.parseDouble('0' + value);
} else if (value.charAt(0) == '0' && length > 1) {
switch(value.charAt(1)) {
case '.':
case 'e':
case 'E':
return Double.parseDouble(value);
case 'b':
case 'B':
{
maybeWarnForFeature(token, Feature.BINARY_LITERALS);
double v = 0;
int c = 1;
while (++c < length) {
v = (v * 2) + binarydigit(value.charAt(c));
}
return v;
}
case 'o':
case 'O':
{
maybeWarnForFeature(token, Feature.OCTAL_LITERALS);
double v = 0;
int c = 1;
while (++c < length) {
v = (v * 8) + octaldigit(value.charAt(c));
}
return v;
}
case 'x':
case 'X':
{
double v = 0;
int c = 1;
while (++c < length) {
v = (v * 0x10) + hexdigit(value.charAt(c));
}
return v;
}
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
double v = 0;
int c = 0;
while (++c < length) {
char digit = value.charAt(c);
if (isOctalDigit(digit)) {
v = (v * 8) + octaldigit(digit);
} else {
errorReporter.error(INVALID_OCTAL_DIGIT, sourceName, lineno(location.start), charno(location.start));
return 0;
}
}
if (inStrictContext()) {
errorReporter.error(INVALID_ES5_STRICT_OCTAL, sourceName, lineno(location.start), charno(location.start));
} else {
errorReporter.warning(INVALID_ES5_STRICT_OCTAL, sourceName, lineno(location.start), charno(location.start));
}
return v;
case '8':
case '9':
errorReporter.error(INVALID_OCTAL_DIGIT, sourceName, lineno(location.start), charno(location.start));
return 0;
default:
throw new IllegalStateException("Unexpected character in number literal: " + value.charAt(1));
}
} else {
return Double.parseDouble(value);
}
}
use of com.google.javascript.jscomp.parsing.parser.util.SourceRange in project closure-compiler by google.
the class Parser method parseParameter.
private ParseTree parseParameter(ParamContext context) {
SourcePosition start = getTreeStartLocation();
ParseTree parameter = null;
if (peek(TokenType.SPREAD)) {
parameter = parseRestParameter();
} else if (peekId()) {
parameter = parseIdentifierExpression();
if (peek(TokenType.QUESTION)) {
eat(TokenType.QUESTION);
parameter = new OptionalParameterTree(getTreeLocation(start), parameter);
}
} else if (context != ParamContext.TYPE_EXPRESSION && peekPatternStart()) {
parameter = parsePattern(PatternKind.INITIALIZER);
} else {
throw new IllegalStateException("parseParameterCalled() without confirming a parameter exists.");
}
ParseTree typeAnnotation = null;
SourceRange typeLocation = null;
if (peek(TokenType.COLON)) {
if (peek(1, TokenType.STRING)) {
eat(TokenType.COLON);
// Specialized Signature
typeAnnotation = parseLiteralExpression();
} else {
typeAnnotation = parseTypeAnnotation();
}
typeLocation = getTreeLocation(getTreeStartLocation());
}
if (context == ParamContext.IMPLEMENTATION && !parameter.isRestParameter() && peek(TokenType.EQUAL)) {
eat(TokenType.EQUAL);
ParseTree defaultValue = parseAssignmentExpression();
parameter = new DefaultParameterTree(getTreeLocation(start), parameter, defaultValue);
}
if (typeAnnotation != null) {
// Must be a direct child of the parameter list.
parameter = new TypedParameterTree(typeLocation, parameter, typeAnnotation);
}
return parameter;
}
Aggregations