fix parsing partial number tokens in other radixes (#3000)
This commit is contained in:
@@ -508,7 +508,13 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
if hexadecimal_digit_char!(c) {
|
if hexadecimal_digit_char!(c) {
|
||||||
self.skip_char(c);
|
self.skip_char(c);
|
||||||
token.push(c);
|
token.push(c);
|
||||||
c = try_nt!(token, self.lookahead_char());
|
c = match self.lookahead_char() {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) if e.is_unexpected_eof() => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -533,7 +539,13 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
if octal_digit_char!(c) {
|
if octal_digit_char!(c) {
|
||||||
self.skip_char(c);
|
self.skip_char(c);
|
||||||
token.push(c);
|
token.push(c);
|
||||||
c = try_nt!(token, self.lookahead_char());
|
c = match self.lookahead_char() {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) if e.is_unexpected_eof() => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -558,7 +570,13 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
if binary_digit_char!(c) {
|
if binary_digit_char!(c) {
|
||||||
self.skip_char(c);
|
self.skip_char(c);
|
||||||
token.push(c);
|
token.push(c);
|
||||||
c = try_nt!(token, self.lookahead_char());
|
c = match self.lookahead_char() {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) if e.is_unexpected_eof() => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -662,9 +680,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
|
|
||||||
fn vacate_with_float(&mut self, mut token: String) -> Result<Number, ParserError> {
|
fn vacate_with_float(&mut self, mut token: String) -> Result<Number, ParserError> {
|
||||||
self.return_char(token.pop().unwrap());
|
self.return_char(token.pop().unwrap());
|
||||||
|
|
||||||
let n = parse_float_lossy(&token)?;
|
let n = parse_float_lossy(&token)?;
|
||||||
|
|
||||||
Ok(Number::Float(float_alloc!(n, self.machine_st.arena)))
|
Ok(Number::Float(float_alloc!(n, self.machine_st.arena)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,12 +702,8 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_integer_by_radix(
|
fn parse_integer_by_radix(&mut self, token: &str, radix: u32) -> Result<Number, ParserError> {
|
||||||
&mut self,
|
i64::from_str_radix(token, radix)
|
||||||
token: &String,
|
|
||||||
radix: u32,
|
|
||||||
) -> Result<Number, ParserError> {
|
|
||||||
i64::from_str_radix(&token, radix)
|
|
||||||
.map(|n| {
|
.map(|n| {
|
||||||
Fixnum::build_with_checked(n)
|
Fixnum::build_with_checked(n)
|
||||||
.map(Number::Fixnum)
|
.map(Number::Fixnum)
|
||||||
@@ -708,7 +720,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn parse_integer(&mut self, token: &String) -> Result<Number, ParserError> {
|
fn parse_integer(&mut self, token: &str) -> Result<Number, ParserError> {
|
||||||
self.parse_integer_by_radix(token, 10)
|
self.parse_integer_by_radix(token, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user