From ddb5b6f32aa871cf2f1fab90d88a13e9d29468ac Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 25 Jan 2020 14:11:04 -0500 Subject: [PATCH] Make function body a list of AtRule rather than token --- src/function.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/function.rs b/src/function.rs index a9077e7..0b3f28c 100644 --- a/src/function.rs +++ b/src/function.rs @@ -1,6 +1,7 @@ use std::iter::Peekable; use std::vec::IntoIter; +use crate::atrule::AtRule; use crate::common::{Pos, Scope, Symbol}; use crate::args::{eat_func_args, FuncArgs}; use crate::utils::devour_whitespace; @@ -10,12 +11,12 @@ use crate::{Token, TokenKind}; pub(crate) struct Function { scope: Scope, args: FuncArgs, - body: Peekable>, + body: Peekable>, } impl Function { - pub fn new(scope: Scope, args: FuncArgs, body: Vec) -> Self { + pub fn new(scope: Scope, args: FuncArgs, body: Vec) -> Self { let body = body.into_iter().peekable(); Function { scope, args, body } } @@ -47,18 +48,16 @@ impl Function { }; let mut nesting = 1; - let mut body = Vec::new(); + let mut body: Vec = Vec::new(); while nesting > 0 { if let Some(tok) = toks.next() { match &tok.kind { - TokenKind::Symbol(Symbol::OpenCurlyBrace) - // interpolation token eats the opening brace but not the closing - | TokenKind::Interpolation => nesting += 1, + TokenKind::AtRule(rule) => body.push(AtRule::from_tokens(&rule, tok.pos, toks, scope)), TokenKind::Symbol(Symbol::CloseCurlyBrace) => nesting -= 1, _ => {} } - body.push(tok) + } else { return Err((pos, String::from("unexpected EOF"))); }