From 84e402023aa057248d1a731d21171c43c49ae628 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 1 Mar 2020 17:06:55 -0500 Subject: [PATCH] @content boilerplate --- src/atrule/mod.rs | 5 +++++ src/function.rs | 3 ++- src/lib.rs | 3 +++ src/mixin.rs | 6 +++++- src/value/ops.rs | 2 +- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/atrule/mod.rs b/src/atrule/mod.rs index 1ef6f21..4b56be9 100644 --- a/src/atrule/mod.rs +++ b/src/atrule/mod.rs @@ -28,6 +28,7 @@ pub(crate) enum AtRule { Function(String, Box), Return(Vec), Charset, + Content, Unknown(UnknownAtRule), For(Vec), } @@ -213,6 +214,7 @@ impl AtRule { scope, super_selector, )?), + AtRuleKind::Content => AtRule::Content, _ => todo!("encountered unimplemented at rule"), }) } @@ -232,6 +234,7 @@ pub enum AtRuleKind { /// and variables from other stylesheets Import, Mixin, + Content, Include, /// Defines custom functions that can be used in SassScript /// expressions @@ -335,6 +338,7 @@ impl From<&str> for AtRuleKind { "viewport" => Self::Viewport, "document" => Self::Document, "counterstyle" => Self::CounterStyle, + "content" => Self::Content, s => Self::Unknown(s.to_owned()), } } @@ -376,6 +380,7 @@ impl Display for AtRuleKind { Self::Viewport => write!(f, "@viewport"), Self::Document => write!(f, "@document"), Self::CounterStyle => write!(f, "@counterstyle"), + Self::Content => write!(f, "@content"), Self::Unknown(s) => write!(f, "@{}", s), } } diff --git a/src/function.rs b/src/function.rs index 8bd7321..7cbdf72 100644 --- a/src/function.rs +++ b/src/function.rs @@ -94,7 +94,8 @@ impl Function { super_selector, ) } - _ => todo!("unimplemented at rule in function body"), + AtRule::For(..) => todo!("@for in function"), + _ => return Err("This at-rule is not allowed here.".into()), } } todo!() diff --git a/src/lib.rs b/src/lib.rs index b217829..a090962 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -502,6 +502,7 @@ impl<'a> StyleSheetParser<'a> { return Err("This at-rule is not allowed here.".into()) } AtRule::For(s) => rules.extend(s), + AtRule::Content => return Err("@content is only allowed within mixin declarations.".into()), u @ AtRule::Unknown(..) => rules.push(Stmt::AtRule(u)), } } @@ -527,6 +528,7 @@ impl<'a> StyleSheetParser<'a> { Expr::Style(s) => stmts.push(Stmt::Style(s)), Expr::AtRule(a) => match a { AtRule::For(s) => stmts.extend(s), + AtRule::Content => return Err("@content is only allowed within mixin declarations.".into()), r => stmts.push(Stmt::AtRule(r)), }, Expr::Styles(s) => stmts.extend(s.into_iter().map(Box::new).map(Stmt::Style)), @@ -692,6 +694,7 @@ pub(crate) fn eat_expr>( AtRule::Warn(a, b) => Ok(Some(Expr::Warn(a, b))), AtRule::Error(pos, err) => Err(SassError::new(err, pos)), AtRule::Return(_) => todo!("@return in unexpected location!"), + AtRule::Content => return Err("@content is only allowed within mixin declarations.".into()), f @ AtRule::For(..) => Ok(Some(Expr::AtRule(f))), u @ AtRule::Unknown(..) => Ok(Some(Expr::AtRule(u))), }; diff --git a/src/mixin.rs b/src/mixin.rs index 37ea43c..c91b849 100644 --- a/src/mixin.rs +++ b/src/mixin.rs @@ -2,6 +2,7 @@ use std::iter::Peekable; use std::vec::IntoIter; use crate::args::{eat_call_args, eat_func_args, CallArgs, FuncArgs}; +use crate::atrule::AtRule; use crate::common::{Scope, Symbol}; use crate::error::{SassError, SassResult}; use crate::selector::Selector; @@ -95,7 +96,10 @@ impl Mixin { let mut stmts = Vec::new(); while let Some(expr) = eat_expr(&mut self.body, &mut self.scope, super_selector)? { match expr { - Expr::AtRule(a) => stmts.push(Stmt::AtRule(a)), + Expr::AtRule(a) => match a { + AtRule::Content => todo!("@content in mixin"), + _ => stmts.push(Stmt::AtRule(a)) + }, Expr::Style(s) => stmts.push(Stmt::Style(s)), Expr::Styles(s) => stmts.extend(s.into_iter().map(Box::new).map(Stmt::Style)), Expr::Include(s) => stmts.extend(s), diff --git a/src/value/ops.rs b/src/value/ops.rs index 44972f6..d2c10f6 100644 --- a/src/value/ops.rs +++ b/src/value/ops.rs @@ -47,7 +47,7 @@ impl Add for Value { } }, // Self::List(..) => todo!(), - Self::Color(c) => match dbg!(&other) { + Self::Color(c) => match other { Self::Ident(s, QuoteKind::Double) | Self::Ident(s, QuoteKind::Single) => { Value::Ident(format!("{}{}", c, s), QuoteKind::Double) }