diff --git a/src/color/mod.rs b/src/color/mod.rs index c0224a2..4beacd0 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -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. diff --git a/src/utils/number.rs b/src/utils/number.rs index d4a5b98..8ddc824 100644 --- a/src/utils/number.rs +++ b/src/utils/number.rs @@ -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>( 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>( 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, }) } diff --git a/src/value/parse.rs b/src/value/parse.rs index 03a1b1f..e63713a 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -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::().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 { diff --git a/src/value/sass_function.rs b/src/value/sass_function.rs index 82d265f..18eb671 100644 --- a/src/value/sass_function.rs +++ b/src/value/sass_function.rs @@ -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