ext/include/iv/lexer.h in iv-phonic-0.0.9 vs ext/include/iv/lexer.h in iv-phonic-0.1.0
- old
+ new
@@ -260,11 +260,11 @@
case '.':
// . Number
Advance();
if (Chars::IsDecimalDigit(c_)) {
// float number parse
- token = ScanNumber(true);
+ token = ScanNumber<true>();
} else {
token = Token::PERIOD;
}
break;
@@ -340,11 +340,11 @@
default:
if (Chars::IsIdentifierStart(c_)) {
token = ScanIdentifier<LexType>(strict);
} else if (Chars::IsDecimalDigit(c_)) {
- token = ScanNumber(false);
+ token = ScanNumber<false>();
} else if (Chars::IsLineTerminator(c_)) {
SkipLineTerminator();
has_line_terminator_before_next_ = true;
token = Token::NOT_FOUND;
} else if (c_ < 0) {
@@ -731,11 +731,12 @@
break;
}
return true;
}
- Token::Type ScanNumber(const bool period) {
+ template<bool period>
+ Token::Type ScanNumber() {
buffer8_.clear();
State type = DECIMAL;
if (period) {
Record8('0');
Record8('.');
@@ -796,19 +797,24 @@
// DecimalDigit."
if (Chars::IsDecimalDigit(c_) || Chars::IsIdentifierStart(c_)) {
return Token::ILLEGAL;
}
- if (type == OCTAL) {
- double val = 0;
- for (typename std::vector<char>::const_iterator it = buffer8_.begin(),
- last = buffer8_.end(); it != last; ++it) {
- val = val * 8 + (*it - '0');
- }
- numeric_ = val;
- } else {
+
+ if (type == DECIMAL) {
const std::string buf(buffer8_.begin(), buffer8_.end());
numeric_ = std::atof(buf.c_str());
+ } else if (type == HEX) {
+ assert(buffer8_.size() > 2); // first 0x
+ numeric_ = ParseIntegerOverflow(buffer8_.begin() + 2,
+ buffer8_.end(),
+ 16);
+ } else {
+ assert(type == OCTAL);
+ assert(buffer8_.size() > 1); // first 0
+ numeric_ = ParseIntegerOverflow(buffer8_.begin() + 1,
+ buffer8_.end(),
+ 8);
}
type_ = type;
return Token::NUMBER;
}