int () { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } int result; if (p == PEEKED_LONG) { result = (int)peekedLong; if (peekedLong != result) { // Make sure no precision was lost casting to 'int'. throw new NumberFormatException("Expected an int but was " + peekedLong + " at line " + getLineNumber() + " column " + getColumnNumber()); } peeked = PEEKED_NONE; return result; } if (p == PEEKED_NUMBER) { int end = position + peekedNumberLength; peekedString = sourceSequence.subSequence(position, end).toString(); position = end; } else if (p == PEEKED_SINGLE_QUOTED || p == PEEKED_DOUBLE_QUOTED) { peekedString = nextQuotedValue(p == PEEKED_SINGLE_QUOTED ? '\'' : '"'); try { result = Integer.parseInt(peekedString); peeked = PEEKED_NONE; return result; } catch (NumberFormatException ignored) { // Fall back to parse as a double below. } } else { throw createParseError("Expected an int but was " + peek()); } peeked = PEEKED_BUFFERED; double asDouble = Double.parseDouble(peekedString); // don't catch this NumberFormatException. result = (int)asDouble; if (result != asDouble) { // Make sure no precision was lost casting to 'int'. throw new NumberFormatException("Expected an int but was " + peekedString + " at line " + getLineNumber() + " column " + getColumnNumber()); } peekedString = null; peeked = PEEKED_NONE; return result; }