diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index 98f4c09..c7accf3 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -22,7 +22,8 @@ pub(crate) fn register(f: &mut BTreeMap) { let alpha = match arg!(args, 3, "alpha"=Value::Dimension(Number::from(1), Unit::None)) { Value::Dimension(n, Unit::None) => n, Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("non-number alpha given to builtin function `rgb()`") + v @ Value::Dimension(..) => return Err(format!("$alpha: Expected {} to have no units or \"%\".", v).into()), + v => return Err(format!("$alpha: {} is not a number.", v).into()), }; Ok(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha))) }); @@ -42,7 +43,8 @@ pub(crate) fn register(f: &mut BTreeMap) { let alpha = match arg!(args, 3, "alpha").eval() { Value::Dimension(n, Unit::None) => n, Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("$alpha: Expected ____ to have no units or \"%\"."), + v @ Value::Dimension(..) => return Err(format!("$alpha: Expected {} to have no units or \"%\".", v).into()), + v => return Err(format!("$alpha: {} is not a number.", v).into()), }; Ok(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha))) }); @@ -70,9 +72,7 @@ pub(crate) fn register(f: &mut BTreeMap) { v => return Err(format!("$color: {} is not a color.", v).into()), }; let degrees = match arg!(args, 1, "degrees").eval() { - Value::Dimension(n, Unit::None) - | Value::Dimension(n, Unit::Percent) - | Value::Dimension(n, Unit::Deg) => n, + Value::Dimension(n, _) => n, _ => todo!("expected either unitless or % number for degrees"), }; Ok(Value::Color(color.adjust_hue(degrees))) @@ -83,9 +83,8 @@ pub(crate) fn register(f: &mut BTreeMap) { v => return Err(format!("$color: {} is not a color.", v).into()), }; let amount = match arg!(args, 1, "amount").eval() { - Value::Dimension(n, Unit::None) => n, - Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for amount"), + Value::Dimension(n, _) => n / Number::from(100), + v => return Err(format!("$amount: {} is not a number.", v).into()) }; Ok(Value::Color(color.lighten(amount))) }); @@ -95,9 +94,8 @@ pub(crate) fn register(f: &mut BTreeMap) { v => return Err(format!("$color: {} is not a color.", v).into()), }; let amount = match arg!(args, 1, "amount").eval() { - Value::Dimension(n, Unit::None) => n, - Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for amount"), + Value::Dimension(n, _) => n / Number::from(100), + v => return Err(format!("$amount: {} is not a number.", v).into()) }; Ok(Value::Color(color.darken(amount))) }); @@ -119,7 +117,7 @@ pub(crate) fn register(f: &mut BTreeMap) { }; let amount = match arg!(args, 1, "amount").eval() { Value::Dimension(n, _) => n / Number::from(100), - v => return Err(format!("$amount: {} is not a number.", v).into()) + v => return Err(format!("$amount: {} is not a number.", v).into()) }; Ok(Value::Color(color.desaturate(amount))) }); diff --git a/src/builtin/color/rgb.rs b/src/builtin/color/rgb.rs index 7b14260..8d5d306 100644 --- a/src/builtin/color/rgb.rs +++ b/src/builtin/color/rgb.rs @@ -122,7 +122,8 @@ pub(crate) fn register(f: &mut BTreeMap) { let alpha = match arg!(args, 1, "alpha").eval() { Value::Dimension(n, Unit::None) => n, Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for alpha"), + v @ Value::Dimension(..) => return Err(format!("$alpha: Expected {} to have no units or \"%\".", v).into()), + v => return Err(format!("$alpha: {} is not a number.", v).into()), }; Ok(Value::Color(color.with_alpha(alpha))) } else { @@ -147,7 +148,8 @@ pub(crate) fn register(f: &mut BTreeMap) { let alpha = match arg!(args, 3, "alpha"=Value::Dimension(Number::from(1), Unit::None)).eval() { Value::Dimension(n, Unit::None) => n, Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for alpha") + v @ Value::Dimension(..) => return Err(format!("$alpha: Expected {} to have no units or \"%\".", v).into()), + v => return Err(format!("$alpha: {} is not a number.", v).into()), }; Ok(Value::Color(Color::from_rgba(red, green, blue, alpha))) } diff --git a/src/lib.rs b/src/lib.rs index 1aa79ff..f8d9abb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,8 +59,8 @@ use std::path::Path; use crate::atrule::{AtRule, AtRuleKind}; use crate::common::{Keyword, Op, Pos, Scope, Symbol, Whitespace}; use crate::css::Css; -pub use crate::error::SassResult; use crate::error::SassError; +pub use crate::error::SassResult; use crate::format::PrettyPrinter; use crate::function::Function; use crate::imports::import; diff --git a/src/main.rs b/src/main.rs index ef6cf36..1e03cde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,9 @@ fn main() { eprintln!("{}", b); std::process::exit(1) } - }.print_as_css(&mut stdout).unwrap(); + } + .print_as_css(&mut stdout) + .unwrap(); } } } diff --git a/src/units.rs b/src/units.rs index 72d34fd..4314ccb 100644 --- a/src/units.rs +++ b/src/units.rs @@ -117,13 +117,9 @@ impl Unit { pub fn kind(&self) -> UnitKind { match self { - Unit::Px - | Unit::Mm - | Unit::In - | Unit::Cm - | Unit::Q - | Unit::Pt - | Unit::Pc => UnitKind::Absolute, + Unit::Px | Unit::Mm | Unit::In | Unit::Cm | Unit::Q | Unit::Pt | Unit::Pc => { + UnitKind::Absolute + } Unit::Em | Unit::Rem | Unit::Lh @@ -132,24 +128,13 @@ impl Unit { | Unit::Cap | Unit::Ic | Unit::Rlh => UnitKind::FontRelative, - Unit::Vw - | Unit::Vh - | Unit::Vmin - | Unit::Vmax - | Unit::Vi - | Unit::Vb => UnitKind::ViewportRelative, - Unit::Deg - | Unit::Grad - | Unit::Rad - | Unit::Turn => UnitKind::Angle, - Unit::S - | Unit::Ms => UnitKind::Time, - Unit::Hz - | Unit::Khz => UnitKind::Frequency, - Unit::Dpi - | Unit::Dpcm - | Unit::Dppx - | Unit::X => UnitKind::Resolution, + Unit::Vw | Unit::Vh | Unit::Vmin | Unit::Vmax | Unit::Vi | Unit::Vb => { + UnitKind::ViewportRelative + } + Unit::Deg | Unit::Grad | Unit::Rad | Unit::Turn => UnitKind::Angle, + Unit::S | Unit::Ms => UnitKind::Time, + Unit::Hz | Unit::Khz => UnitKind::Frequency, + Unit::Dpi | Unit::Dpcm | Unit::Dppx | Unit::X => UnitKind::Resolution, Unit::None => UnitKind::None, _ => UnitKind::Other, } diff --git a/src/value/number.rs b/src/value/number.rs index c9cdf25..410bfcf 100644 --- a/src/value/number.rs +++ b/src/value/number.rs @@ -1,6 +1,8 @@ use std::convert::From; use std::fmt::{self, Display, Write}; -use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Sub, SubAssign, Neg}; +use std::ops::{ + Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign, +}; use num_bigint::BigInt; use num_rational::BigRational; @@ -201,8 +203,6 @@ impl Neg for Number { type Output = Self; fn neg(self) -> Self { - Number { - val: -self.val, - } + Number { val: -self.val } } -} \ No newline at end of file +} diff --git a/src/value/parse.rs b/src/value/parse.rs index d33b0ee..9477d13 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -298,9 +298,7 @@ impl Value { } Ok(Value::Ident(s, QuoteKind::Single)) } - TokenKind::Variable(ref v) => { - Ok(scope.get_var(v).expect("expected variable").clone()) - } + TokenKind::Variable(ref v) => Ok(scope.get_var(v).expect("expected variable").clone()), TokenKind::Interpolation => { let mut s = parse_interpolation(toks, scope) .iter()