remove is_float field of ParsedNumber
This commit is contained in:
parent
bcbf3f4a90
commit
bc09e49c89
@ -1,4 +1,5 @@
|
||||
//! A color is internally represented as either RGBA or HSLA.
|
||||
//!
|
||||
//! Colors can be constructed in SASS through names (e.g. red, blue, aqua)
|
||||
//! or the builtin functions `rgb()`, `rgba()`, `hsl()`, and `hsla()`,
|
||||
//! all of which can accept 1-4 arguments.
|
||||
|
@ -9,12 +9,28 @@ use crate::Token;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ParsedNumber {
|
||||
/// The full number excluding the decimal
|
||||
///
|
||||
/// E.g. for `1.23`, this would be `"123"`
|
||||
pub num: String,
|
||||
|
||||
/// The length of the decimal
|
||||
///
|
||||
/// E.g. for `1.23`, this would be `2`
|
||||
pub dec_len: usize,
|
||||
|
||||
/// 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
|
||||
// TODO: maybe we just return a bigint?
|
||||
pub times_ten: String,
|
||||
|
||||
/// Whether or not `times_ten` is negative
|
||||
///
|
||||
/// E.g. for `1e-23` this would be `true`,
|
||||
/// for `1e23` this would be `false`
|
||||
pub times_ten_is_postive: bool,
|
||||
pub is_float: bool,
|
||||
}
|
||||
|
||||
impl ParsedNumber {
|
||||
@ -23,14 +39,12 @@ impl ParsedNumber {
|
||||
dec_len: usize,
|
||||
times_ten: String,
|
||||
times_ten_is_postive: bool,
|
||||
is_float: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
num,
|
||||
dec_len,
|
||||
times_ten,
|
||||
times_ten_is_postive,
|
||||
is_float,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,7 +63,7 @@ pub(crate) fn eat_number<I: Iterator<Item = Token>>(
|
||||
|
||||
if toks.peek().is_none() {
|
||||
return Ok(Spanned {
|
||||
node: ParsedNumber::new(whole, 0, String::new(), true, false),
|
||||
node: ParsedNumber::new(whole, 0, String::new(), true),
|
||||
span,
|
||||
});
|
||||
}
|
||||
@ -110,7 +124,7 @@ pub(crate) fn eat_number<I: Iterator<Item = Token>>(
|
||||
whole.push_str(&dec);
|
||||
|
||||
Ok(Spanned {
|
||||
node: ParsedNumber::new(whole, dec.len(), times_ten, times_ten_is_postive, is_float),
|
||||
node: ParsedNumber::new(whole, dec.len(), times_ten, times_ten_is_postive),
|
||||
span,
|
||||
})
|
||||
}
|
||||
|
@ -643,10 +643,10 @@ impl Value {
|
||||
)
|
||||
};
|
||||
|
||||
let n = if val.is_float {
|
||||
BigRational::new(val.num.parse().unwrap(), pow(BigInt::from(10), val.dec_len))
|
||||
} else {
|
||||
let n = if val.dec_len == 0 {
|
||||
BigRational::new_raw(val.num.parse::<BigInt>().unwrap(), BigInt::one())
|
||||
} else {
|
||||
BigRational::new(val.num.parse().unwrap(), pow(BigInt::from(10), val.dec_len))
|
||||
} * if val.times_ten_is_postive {
|
||||
BigRational::new_raw(times_ten, BigInt::one())
|
||||
} else {
|
||||
|
@ -20,6 +20,7 @@ use crate::selector::Selector;
|
||||
use crate::value::Value;
|
||||
|
||||
/// A SASS function
|
||||
///
|
||||
/// See toplevel documentation for more information
|
||||
///
|
||||
/// The function name is stored in addition to the body
|
||||
|
Loading…
x
Reference in New Issue
Block a user