private Token readNumber(int ch) throws IOException
{
_allowPattern = false;
Token token = createToken();
GenericInputStream input = _input;
StringBuffer image = _image;
int line;
int column;
int state;
int kind = INTEGER_LITERAL;
image.setLength(0);
image.append((char)ch);
if (ch == '0') {
state = STATE_START;
} else {
state = STATE_DECIMAL;
}
finished:
for(;;) {
line = input.getLineNumber();
column = input.getColumnNumber();
ch = input.read();
if (ch == -1) {
break;
}
switch(state) {
case STATE_START:
switch(ch) {
case 'x':
case 'X':
state = STATE_HEX;
break;
case 'b':
case 'B':
state = STATE_BINARY;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
state = STATE_DECIMAL;
break;
case '.':
state = STATE_FRACTION_START;
kind = FLOATING_POINT_LITERAL;
break;
default:
break finished;
}
break;
case STATE_DECIMAL:
switch(ch) {
case '.':
state = STATE_FRACTION_START;
kind = FLOATING_POINT_LITERAL;
break;
case 'e':
case 'E':
state = STATE_EXPONENT_START;
kind = FLOATING_POINT_LITERAL;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
break;
default:
break finished;
}
break;
case STATE_HEX:
switch(ch) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
break;
default:
if (Character.isJavaIdentifierPart((char)ch)) {
_parser.error(_parser.toLocation(line, column),
"Invalid hexadecimal number");
}
break finished;
}
break;
case STATE_BINARY:
switch(ch) {
case '0': case '1':
break;
default:
if (Character.isJavaIdentifierPart((char)ch)) {
_parser.error(_parser.toLocation(line, column),
"Invalid binary number");
}
break finished;
}
break;
case STATE_FRACTION_START:
if (ch == '.') {
Token range = new Token();
range.kind = RANGE;
range.image = "..";
range.beginLine = line;
range.beginColumn = column - 1;
range.endLine = line;
range.endColumn = column;
token.next = range;
line = input.getLineNumber();
column = input.getColumnNumber();
ch = input.read();
kind = INTEGER_LITERAL;
image.setLength(image.length() - 1);
break finished;