diff --git a/src/atrule.rs b/src/atrule.rs index 24fc4aa..0a51beb 100644 --- a/src/atrule.rs +++ b/src/atrule.rs @@ -164,19 +164,21 @@ impl AtRule { }; let mut body = Vec::new(); let mut n = 1; - for tok in toks { + while let Some(tok) = toks.next() { match tok.kind { TokenKind::Symbol(Symbol::OpenCurlyBrace) => n += 1, TokenKind::Symbol(Symbol::CloseCurlyBrace) => n -= 1, TokenKind::Interpolation => n += 1, _ => {} } - body.push(tok); if n == 0 { break; } + body.push(tok); } + devour_whitespace_or_comment(toks); + let mut scope = scope.clone(); if from < to { for i in from..(to + through) { diff --git a/src/css.rs b/src/css.rs index c50bf19..a45c096 100644 --- a/src/css.rs +++ b/src/css.rs @@ -145,8 +145,7 @@ impl Css { writeln!(buf, "{}@{} {} {{", padding, u.name, u.params)?; } Css::from_stylesheet(StyleSheet::from_stmts(u.body.clone())) - .pretty_print(buf, nesting + 1) - .unwrap(); + .pretty_print(buf, nesting + 1)?; writeln!(buf, "{}}}", padding)?; } _ => todo!(), diff --git a/src/lib.rs b/src/lib.rs index 78cd870..1ca5723 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -498,7 +498,10 @@ impl<'a> StyleSheetParser<'a> { while let Some(expr) = eat_expr(&mut self.lexer, scope, super_selector)? { match expr { Expr::Style(s) => stmts.push(Stmt::Style(*s)), - Expr::AtRule(s) => stmts.push(Stmt::AtRule(s)), + Expr::AtRule(a) => match a { + AtRule::For(s) => stmts.extend(s), + r => stmts.push(Stmt::AtRule(r)), + }, Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)), Expr::MixinDecl(name, mixin) => { scope.insert_mixin(&name, *mixin); diff --git a/src/value/parse.rs b/src/value/parse.rs index 0f7e104..32bf0b3 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -160,7 +160,7 @@ impl Value { let kind = if let Some(tok) = toks.next() { tok.kind } else { - return Err("Unexpected EOF".into()); + panic!("Unexpected EOF"); }; match kind { TokenKind::Number(val) => { diff --git a/tests/for.rs b/tests/for.rs index d8c067a..8e4041d 100644 --- a/tests/for.rs +++ b/tests/for.rs @@ -33,3 +33,8 @@ test!( "@for $x from 1 to 3 {\n $limit: $x;\n\n a {\n color: $limit;\n }\n}\n", "a {\n color: 1;\n}\n\na {\n color: 2;\n}\n" ); +test!( + for_styles, + "a {\n @for $i from 1 to 3 {\n color: $i;\n }\n}\n", + "a {\n color: 1;\n color: 2;\n}\n" +);