diff --git a/src/lib.rs b/src/lib.rs index 32559ce..9aa4064 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -581,12 +581,18 @@ pub(crate) fn eat_expr>( } } TokenKind::Interpolation => { + let mut n = 0; while let Some(tok) = toks.next() { - if tok.kind == TokenKind::Symbol(Symbol::CloseCurlyBrace) { - values.push(tok); - break; + 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; + } } } _ => match toks.next() { @@ -730,11 +736,11 @@ mod test_variables { "a {\n $c: red;\nb {\n $c: blue;\n }\n color: $c;\n}\n", "a {\n color: blue;\n}\n" ); - // test!( - // nested_interpolation, - // "$a: red; a {\n color: #{#{$a}};\n}\n", - // "a {\n color: red;\n}\n" - // ); + test!( + nested_interpolation, + "$a: red; a {\n color: #{#{$a}};\n}\n", + "a {\n color: red;\n}\n" + ); } #[cfg(test)] diff --git a/src/utils.rs b/src/utils.rs index adba6fe..5bdaad9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -48,17 +48,18 @@ pub(crate) fn deref_variable(name: &str, scope: &Scope) -> Vec { } pub(crate) fn eat_interpolation>( - tokens: &mut Peekable, + tokens: &mut I, scope: &Scope, ) -> Vec { let mut val = Vec::new(); - for tok in tokens { + while let Some(tok) = tokens.next() { match tok.kind { TokenKind::Symbol(Symbol::CloseCurlyBrace) => break, TokenKind::Symbol(Symbol::OpenCurlyBrace) => { todo!("invalid character in interpolation") } TokenKind::Variable(ref v) => val.extend(deref_variable(v, scope)), + TokenKind::Interpolation => val.extend(eat_interpolation(tokens, scope)), _ => val.push(tok), } }