@content boilerplate

This commit is contained in:
ConnorSkees 2020-03-01 17:06:55 -05:00
parent 3181d58441
commit 84e402023a
5 changed files with 16 additions and 3 deletions

View File

@ -28,6 +28,7 @@ pub(crate) enum AtRule {
Function(String, Box<Function>),
Return(Vec<Token>),
Charset,
Content,
Unknown(UnknownAtRule),
For(Vec<Stmt>),
}
@ -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),
}
}

View File

@ -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!()

View File

@ -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<I: Iterator<Item = Token>>(
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))),
};

View File

@ -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),

View File

@ -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)
}