2020-07-09 11:56:58 -04:00
|
|
|
use std::vec::IntoIter;
|
|
|
|
|
2020-04-20 14:49:29 -04:00
|
|
|
use peekmore::PeekMoreIterator;
|
|
|
|
|
2020-07-28 18:09:23 -04:00
|
|
|
use crate::Token;
|
2020-04-20 14:49:29 -04:00
|
|
|
|
2020-04-28 14:46:40 -04:00
|
|
|
#[derive(Debug)]
|
2020-04-28 12:15:10 -04:00
|
|
|
pub(crate) struct ParsedNumber {
|
2020-04-28 15:28:50 -04:00
|
|
|
/// The full number excluding the decimal
|
|
|
|
///
|
|
|
|
/// E.g. for `1.23`, this would be `"123"`
|
2020-04-28 13:18:54 -04:00
|
|
|
pub num: String,
|
2020-04-28 15:28:50 -04:00
|
|
|
|
|
|
|
/// The length of the decimal
|
|
|
|
///
|
|
|
|
/// E.g. for `1.23`, this would be `2`
|
2020-04-28 13:18:54 -04:00
|
|
|
pub dec_len: usize,
|
2020-04-28 15:28:50 -04:00
|
|
|
|
|
|
|
/// The number following e in a scientific notated number
|
|
|
|
///
|
|
|
|
/// E.g. for `1e23`, this would be `"23"`,
|
|
|
|
/// for `1`, this would be an empty string
|
2020-04-28 12:15:10 -04:00
|
|
|
// TODO: maybe we just return a bigint?
|
2020-04-28 13:18:54 -04:00
|
|
|
pub times_ten: String,
|
2020-04-28 15:28:50 -04:00
|
|
|
|
|
|
|
/// Whether or not `times_ten` is negative
|
|
|
|
///
|
|
|
|
/// E.g. for `1e-23` this would be `true`,
|
|
|
|
/// for `1e23` this would be `false`
|
2020-04-28 12:15:10 -04:00
|
|
|
pub times_ten_is_postive: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ParsedNumber {
|
2020-04-28 15:14:44 -04:00
|
|
|
pub const fn new(
|
2020-04-28 13:18:54 -04:00
|
|
|
num: String,
|
|
|
|
dec_len: usize,
|
|
|
|
times_ten: String,
|
|
|
|
times_ten_is_postive: bool,
|
|
|
|
) -> Self {
|
2020-04-28 12:15:10 -04:00
|
|
|
Self {
|
2020-04-28 13:18:54 -04:00
|
|
|
num,
|
|
|
|
dec_len,
|
2020-04-28 12:15:10 -04:00
|
|
|
times_ten,
|
|
|
|
times_ten_is_postive,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 11:56:58 -04:00
|
|
|
pub(crate) fn eat_whole_number(toks: &mut PeekMoreIterator<IntoIter<Token>>) -> String {
|
2020-07-05 17:59:48 +08:00
|
|
|
let mut buf = String::new();
|
2020-04-28 12:15:10 -04:00
|
|
|
while let Some(c) = toks.peek() {
|
2020-05-24 13:08:31 -04:00
|
|
|
if !c.kind.is_ascii_digit() {
|
2020-04-28 12:15:10 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
let tok = toks.next().unwrap();
|
|
|
|
buf.push(tok.kind);
|
|
|
|
}
|
2020-07-05 17:59:48 +08:00
|
|
|
buf
|
2020-04-20 14:49:29 -04:00
|
|
|
}
|