This commit is contained in:
ConnorSkees 2020-02-29 16:13:57 -05:00
parent 5367cb315a
commit 624cf06f69
9 changed files with 20 additions and 20 deletions

View File

@ -269,8 +269,8 @@ fn eat_unknown_atrule_body<I: Iterator<Item = Token>>(
while let Some(expr) = eat_expr(toks, &scope, super_selector)? { while let Some(expr) = eat_expr(toks, &scope, super_selector)? {
match expr { match expr {
Expr::AtRule(a) => stmts.push(Stmt::AtRule(a)), Expr::AtRule(a) => stmts.push(Stmt::AtRule(a)),
Expr::Style(s) => stmts.push(Stmt::Style(*s)), Expr::Style(s) => stmts.push(Stmt::Style(s)),
Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)), Expr::Styles(s) => stmts.extend(s.into_iter().map(Box::new).map(Stmt::Style)),
Expr::Include(s) => stmts.extend(s), Expr::Include(s) => stmts.extend(s),
Expr::MixinDecl(..) | Expr::FunctionDecl(..) | Expr::Debug(..) | Expr::Warn(..) => { Expr::MixinDecl(..) | Expr::FunctionDecl(..) | Expr::Debug(..) | Expr::Warn(..) => {
todo!() todo!()

View File

@ -79,7 +79,7 @@ impl Css {
Stmt::Style(s) => vals Stmt::Style(s) => vals
.get_mut(0) .get_mut(0)
.expect("expected block to exist") .expect("expected block to exist")
.push_style(s), .push_style(*s),
Stmt::MultilineComment(s) => vals Stmt::MultilineComment(s) => vals
.get_mut(0) .get_mut(0)
.expect("expected block to exist") .expect("expected block to exist")

View File

@ -139,7 +139,7 @@ impl<'a> Iterator for Lexer<'a> {
if !v.is_ascii() { if !v.is_ascii() {
IS_UTF8.store(true, Ordering::Relaxed); IS_UTF8.store(true, Ordering::Relaxed);
} }
TokenKind::Unknown(v.clone()) TokenKind::Unknown(v)
} }
}; };
self.pos.next_char(); self.pos.next_char();

View File

@ -200,7 +200,7 @@ pub struct StyleSheet(Vec<Stmt>);
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) enum Stmt { pub(crate) enum Stmt {
/// A [`Style`](/grass/style/struct.Style) /// A [`Style`](/grass/style/struct.Style)
Style(Style), Style(Box<Style>),
/// A [`RuleSet`](/grass/struct.RuleSet.html) /// A [`RuleSet`](/grass/struct.RuleSet.html)
RuleSet(RuleSet), RuleSet(RuleSet),
/// A multiline comment: `/* foo bar */` /// A multiline comment: `/* foo bar */`
@ -228,7 +228,7 @@ pub(crate) struct RuleSet {
} }
impl RuleSet { impl RuleSet {
pub(crate) fn new() -> RuleSet { pub(crate) const fn new() -> RuleSet {
RuleSet { RuleSet {
selector: Selector::new(), selector: Selector::new(),
rules: Vec::new(), rules: Vec::new(),
@ -497,12 +497,12 @@ impl<'a> StyleSheetParser<'a> {
let mut stmts = Vec::new(); let mut stmts = Vec::new();
while let Some(expr) = eat_expr(&mut self.lexer, scope, super_selector)? { while let Some(expr) = eat_expr(&mut self.lexer, scope, super_selector)? {
match expr { match expr {
Expr::Style(s) => stmts.push(Stmt::Style(*s)), Expr::Style(s) => stmts.push(Stmt::Style(s)),
Expr::AtRule(a) => match a { Expr::AtRule(a) => match a {
AtRule::For(s) => stmts.extend(s), AtRule::For(s) => stmts.extend(s),
r => stmts.push(Stmt::AtRule(r)), r => stmts.push(Stmt::AtRule(r)),
}, },
Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)), Expr::Styles(s) => stmts.extend(s.into_iter().map(Box::new).map(Stmt::Style)),
Expr::MixinDecl(name, mixin) => { Expr::MixinDecl(name, mixin) => {
scope.insert_mixin(&name, *mixin); scope.insert_mixin(&name, *mixin);
} }

View File

@ -95,8 +95,8 @@ impl Mixin {
while let Some(expr) = eat_expr(&mut self.body, &self.scope, super_selector)? { while let Some(expr) = eat_expr(&mut self.body, &self.scope, super_selector)? {
match expr { match expr {
Expr::AtRule(a) => stmts.push(Stmt::AtRule(a)), Expr::AtRule(a) => stmts.push(Stmt::AtRule(a)),
Expr::Style(s) => stmts.push(Stmt::Style(*s)), Expr::Style(s) => stmts.push(Stmt::Style(s)),
Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)), Expr::Styles(s) => stmts.extend(s.into_iter().map(Box::new).map(Stmt::Style)),
Expr::Include(s) => stmts.extend(s), Expr::Include(s) => stmts.extend(s),
Expr::FunctionDecl(..) => { Expr::FunctionDecl(..) => {
return Err("Mixins may not contain function declarations.".into()) return Err("Mixins may not contain function declarations.".into())

View File

@ -375,7 +375,7 @@ impl Attribute {
} }
q @ TokenKind::Symbol(Symbol::DoubleQuote) q @ TokenKind::Symbol(Symbol::DoubleQuote)
| q @ TokenKind::Symbol(Symbol::SingleQuote) => { | q @ TokenKind::Symbol(Symbol::SingleQuote) => {
parse_quoted_string(toks, scope, q)?.to_string() parse_quoted_string(toks, scope, &q)?.to_string()
} }
_ => return Err("Expected identifier.".into()), _ => return Err("Expected identifier.".into()),
} }
@ -437,7 +437,7 @@ impl Attribute {
} }
q @ TokenKind::Symbol(Symbol::DoubleQuote) q @ TokenKind::Symbol(Symbol::DoubleQuote)
| q @ TokenKind::Symbol(Symbol::SingleQuote) => { | q @ TokenKind::Symbol(Symbol::SingleQuote) => {
parse_quoted_string(toks, scope, q)?.to_string() parse_quoted_string(toks, scope, &q)?.to_string()
} }
_ => return Err("Expected identifier.".into()), _ => return Err("Expected identifier.".into()),
} }

View File

@ -88,7 +88,7 @@ impl<'a> StyleParser<'a> {
| ref q @ TokenKind::Symbol(Symbol::SingleQuote) => { | ref q @ TokenKind::Symbol(Symbol::SingleQuote) => {
let q = q.clone(); let q = q.clone();
toks.next(); toks.next();
let (s, q) = if let Value::Ident(s, q) = parse_quoted_string(toks, scope, q)? { let (s, q) = if let Value::Ident(s, q) = parse_quoted_string(toks, scope, &q)? {
(s, q) (s, q)
} else { } else {
unreachable!() unreachable!()

View File

@ -54,7 +54,7 @@ pub(crate) fn parse_interpolation<I: Iterator<Item = Token>>(
} }
q @ TokenKind::Symbol(Symbol::DoubleQuote) q @ TokenKind::Symbol(Symbol::DoubleQuote)
| q @ TokenKind::Symbol(Symbol::SingleQuote) => { | q @ TokenKind::Symbol(Symbol::SingleQuote) => {
val.push_str(&parse_quoted_string(tokens, scope, q)?.to_string()) val.push_str(&parse_quoted_string(tokens, scope, &q)?.to_string())
} }
TokenKind::Variable(ref v) => { TokenKind::Variable(ref v) => {
val.push_str(&scope.get_var(v)?.clone().unquote().to_string()) val.push_str(&scope.get_var(v)?.clone().unquote().to_string())
@ -159,7 +159,7 @@ pub(crate) fn flatten_ident<I: Iterator<Item = Token>>(
pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>( pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
toks: &mut Peekable<I>, toks: &mut Peekable<I>,
scope: &Scope, scope: &Scope,
q: TokenKind, q: &TokenKind,
) -> SassResult<Value> { ) -> SassResult<Value> {
let mut s = String::new(); let mut s = String::new();
let mut is_escaped = false; let mut is_escaped = false;
@ -167,7 +167,7 @@ pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
while let Some(tok) = toks.next() { while let Some(tok) = toks.next() {
match tok.kind { match tok.kind {
TokenKind::Symbol(Symbol::DoubleQuote) TokenKind::Symbol(Symbol::DoubleQuote)
if !is_escaped && q == TokenKind::Symbol(Symbol::DoubleQuote) => if !is_escaped && q == &TokenKind::Symbol(Symbol::DoubleQuote) =>
{ {
break break
} }
@ -177,7 +177,7 @@ pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
continue; continue;
} }
TokenKind::Symbol(Symbol::SingleQuote) TokenKind::Symbol(Symbol::SingleQuote)
if !is_escaped && q == TokenKind::Symbol(Symbol::SingleQuote) => if !is_escaped && q == &TokenKind::Symbol(Symbol::SingleQuote) =>
{ {
break break
} }

View File

@ -17,7 +17,7 @@ use crate::{Token, TokenKind};
use super::number::Number; use super::number::Number;
fn parse_hex(s: String) -> Value { fn parse_hex(s: &str) -> Value {
match s.len() { match s.len() {
3 => { 3 => {
let v = match u16::from_str_radix(&s, 16) { let v = match u16::from_str_radix(&s, 16) {
@ -213,7 +213,7 @@ impl Value {
TokenKind::Symbol(Symbol::BitAnd) => { TokenKind::Symbol(Symbol::BitAnd) => {
Ok(Value::Ident(String::from("&"), QuoteKind::None)) Ok(Value::Ident(String::from("&"), QuoteKind::None))
} }
TokenKind::Symbol(Symbol::Hash) => Ok(parse_hex(flatten_ident(toks, scope)?)), TokenKind::Symbol(Symbol::Hash) => Ok(parse_hex(&flatten_ident(toks, scope)?)),
// TokenKind::Interpolation => { // TokenKind::Interpolation => {
// Ok(Value::Ident( // Ok(Value::Ident(
// parse_interpolation(toks, scope) // parse_interpolation(toks, scope)
@ -283,7 +283,7 @@ impl Value {
} }
} }
q @ TokenKind::Symbol(Symbol::DoubleQuote) q @ TokenKind::Symbol(Symbol::DoubleQuote)
| q @ TokenKind::Symbol(Symbol::SingleQuote) => parse_quoted_string(toks, scope, q), | q @ TokenKind::Symbol(Symbol::SingleQuote) => parse_quoted_string(toks, scope, &q),
TokenKind::Variable(ref v) => Ok(scope.get_var(v)?.clone()), TokenKind::Variable(ref v) => Ok(scope.get_var(v)?.clone()),
TokenKind::Interpolation => { TokenKind::Interpolation => {
let mut s = parse_interpolation(toks, scope)? let mut s = parse_interpolation(toks, scope)?