diff --git a/src/lib.rs b/src/lib.rs index 3de7201..bfa07b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,8 @@ clippy::let_underscore_must_use, // this is too pedantic -- it results in some names being less explicit // than they should - clippy::module_name_repetitions + clippy::module_name_repetitions, + clippy::option_unwrap_used, )] #![cfg_attr(feature = "nightly", feature(track_caller))] // todo! handle erroring on styles at the toplevel @@ -207,8 +208,8 @@ enum Expr { /// A variable declaration `$var: 1px` VariableDecl(String, Value), /// A mixin declaration `@mixin foo {}` - MixinDecl(String, Mixin), - FunctionDecl(String, Function), + MixinDecl(String, Box), + FunctionDecl(String, Box), /// An include statement `@include foo;` Include(Vec), /// A multiline comment: `/* foobar */` @@ -434,7 +435,7 @@ impl<'a> StyleSheetParser<'a> { } } TokenKind::Symbol(Symbol::BitAnd) => { - return Err(SassError::new("Base-level rules cannot contain the parent-selector-referencing character '&'.", pos.clone())) + return Err(SassError::new("Base-level rules cannot contain the parent-selector-referencing character '&'.", *pos)) } _ => match dbg!(self.lexer.next()) { Some(Token { pos, .. }) => self.error(pos, "unexpected toplevel token"), @@ -452,12 +453,13 @@ impl<'a> StyleSheetParser<'a> { { match expr { Expr::Style(s) => stmts.push(Stmt::Style(s)), + #[allow(clippy::redundant_closure)] Expr::Styles(s) => stmts.extend(s.into_iter().map(|s| Stmt::Style(s))), Expr::MixinDecl(name, mixin) => { - scope.mixins.insert(name, mixin); + scope.mixins.insert(name, *mixin); } Expr::FunctionDecl(name, func) => { - scope.functions.insert(name, func); + scope.functions.insert(name, *func); } Expr::Selector(s) => { self.scope += 1; @@ -517,7 +519,7 @@ pub(crate) fn eat_expr>( devour_whitespace(toks); // special edge case where there was no space between the colon // in a style `color:red`. todo: refactor - let mut v = values.clone().into_iter().peekable(); + let mut v = values.into_iter().peekable(); let property = Style::parse_property(&mut v, scope, super_selector, String::new()); let value = Style::parse_value(&mut v, scope, super_selector); return Ok(Some(Expr::Style(Style { property, value }))); @@ -531,8 +533,9 @@ pub(crate) fn eat_expr>( // special edge case where there was no space between the colon // and no semicolon following the style // in a style `color:red`. todo: refactor - let mut v = values.clone().into_iter().peekable(); - let property = Style::parse_property(&mut v, scope, super_selector, String::new()); + let mut v = values.into_iter().peekable(); + let property = + Style::parse_property(&mut v, scope, super_selector, String::new()); let value = Style::parse_value(&mut v, scope, super_selector); return Ok(Some(Expr::Style(Style { property, value }))); } @@ -598,8 +601,8 @@ pub(crate) fn eat_expr>( }) = toks.next() { return match AtRule::from_tokens(rule, pos, toks, scope) { - AtRule::Mixin(name, mixin) => Ok(Some(Expr::MixinDecl(name, *mixin))), - AtRule::Function(name, func) => Ok(Some(Expr::FunctionDecl(name, *func))), + AtRule::Mixin(name, mixin) => Ok(Some(Expr::MixinDecl(name, mixin))), + AtRule::Function(name, func) => Ok(Some(Expr::FunctionDecl(name, func))), AtRule::Charset(_) => todo!("@charset as expr"), AtRule::Debug(a, b) => Ok(Some(Expr::Debug(a, b))), AtRule::Warn(a, b) => Ok(Some(Expr::Warn(a, b))), diff --git a/src/style.rs b/src/style.rs index e7746b6..42f2f2b 100644 --- a/src/style.rs +++ b/src/style.rs @@ -188,13 +188,13 @@ impl<'a> StyleParser<'a> { }; } devour_whitespace(toks); - if !super_property.is_empty() { + if super_property.is_empty() { + property + } else { super_property.reserve(1 + property.len()); super_property.push('-'); super_property.push_str(&property); super_property - } else { - property } } } diff --git a/src/value.rs b/src/value.rs index 5575b1d..a3aa67b 100644 --- a/src/value.rs +++ b/src/value.rs @@ -83,19 +83,20 @@ impl Add for Value { fn add(self, other: Self) -> Self { match self { - Self::Important => todo!(), - Self::True => todo!(), - Self::False => todo!(), - Self::Null => todo!(), + // Self::Important => todo!(), + // Self::True => todo!(), + // Self::False => todo!(), + // Self::Null => todo!(), Self::Dimension(num, unit) => match other { Self::Dimension(num2, unit2) => Value::Dimension(num + num2, unit), _ => todo!(), }, - Self::List(..) => todo!(), - Self::Color(..) => todo!(), - Self::BinaryOp(..) => todo!(), - Self::Paren(..) => todo!(), - Self::Ident(..) => todo!(), + // Self::List(..) => todo!(), + // Self::Color(..) => todo!(), + // Self::BinaryOp(..) => todo!(), + // Self::Paren(..) => todo!(), + // Self::Ident(..) => todo!(), + _ => todo!(), } } } @@ -148,7 +149,9 @@ impl Value { None => return Some(left), }; match next.kind { - TokenKind::Symbol(Symbol::SemiColon) => Some(left), + TokenKind::Symbol(Symbol::SemiColon) | TokenKind::Symbol(Symbol::CloseParen) => { + Some(left) + } TokenKind::Symbol(Symbol::Comma) => { toks.next(); devour_whitespace_or_comment(toks); @@ -158,7 +161,6 @@ impl Value { }; Some(Value::List(vec![left, right], ListSeparator::Comma)) } - TokenKind::Symbol(Symbol::CloseParen) => Some(left), TokenKind::Symbol(Symbol::Plus) | TokenKind::Symbol(Symbol::Minus) | TokenKind::Op(_) diff --git a/tests/macros.rs b/tests/macros.rs index 54c6b43..43b31b4 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -7,9 +7,9 @@ macro_rules! test { fn $func() { let mut buf = Vec::new(); grass::StyleSheet::new($input) - .expect(concat!("failed to parse on ", $input)) - .print_as_css(&mut buf) - .expect(concat!("failed to pretty print on ", $input)); + .expect(concat!("failed to parse on ", $input)) + .print_as_css(&mut buf) + .expect(concat!("failed to pretty print on ", $input)); assert_eq!( String::from($input), String::from_utf8(buf).expect("produced invalid utf8") @@ -30,4 +30,4 @@ macro_rules! test { ); } }; -} \ No newline at end of file +}