From 21515214cb047624a96e0b93fcf2e171c0283051 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 20 Jan 2020 18:56:23 -0500 Subject: [PATCH] Refactor interpolation eating --- src/lib.rs | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a007b7f..64f7d76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -604,21 +604,7 @@ pub(crate) fn eat_expr>( } } } - TokenKind::Interpolation => { - let mut n = 0; - 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, - _ => {}, - } - values.push(tok); - if n == 0 { - break; - } - } - } + TokenKind::Interpolation => values.extend(eat_interpolation(toks)), _ => match toks.next() { Some(tok) => values.push(tok), _ => unsafe { std::hint::unreachable_unchecked() }, @@ -628,6 +614,24 @@ pub(crate) fn eat_expr>( Ok(None) } +fn eat_interpolation>(toks: &mut Peekable) -> Vec { + let mut vals = Vec::new(); + let mut n = 0; + 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, + _ => {} + } + vals.push(tok); + if n == 0 { + break; + } + } + vals +} + /// Functions that print to stdout or stderr impl<'a> StyleSheetParser<'a> { fn debug(&self, pos: Pos, message: &str) {