From 6faebf5105a5103249ada5586ab36933694ee4e9 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 2 Feb 2020 21:11:22 -0500 Subject: [PATCH] HACK: parse interpolations into values then tokens --- src/utils.rs | 12 ++++++++---- src/value.rs | 10 ++++++++-- tests/selectors.rs | 15 ++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 674e176..78422d2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -48,9 +48,6 @@ pub(crate) fn parse_interpolation>( while let Some(tok) = tokens.next() { match tok.kind { TokenKind::Symbol(Symbol::CloseCurlyBrace) => break, - TokenKind::Symbol(Symbol::SingleQuote) | TokenKind::Symbol(Symbol::DoubleQuote) => { - continue - } TokenKind::Symbol(Symbol::OpenCurlyBrace) => { todo!("invalid character in interpolation") } @@ -61,7 +58,14 @@ pub(crate) fn parse_interpolation>( _ => val.push(tok), } } - val + Lexer::new( + &Value::from_tokens(&mut val.into_iter().peekable(), scope) + .unwrap() + .to_string() + .replace("\"", "") + .replace("'", ""), + ) + .collect::>() } pub(crate) struct VariableDecl { diff --git a/src/value.rs b/src/value.rs index 4c84988..56e2e68 100644 --- a/src/value.rs +++ b/src/value.rs @@ -220,8 +220,11 @@ impl Value { todo!() } - pub fn unquote(&mut self) -> &mut Self { - todo!() + pub fn unquote(self) -> Self { + match self { + Self::Ident(s1, _) => Self::Ident(s1, QuoteKind::None), + _ => todo!(), + } } pub fn from_tokens>( @@ -327,6 +330,9 @@ impl Value { ); Some(Value::Paren(Box::new(val))) } + TokenKind::Symbol(Symbol::BitAnd) => { + Some(Value::Ident(String::from("&"), QuoteKind::None)) + } TokenKind::Ident(mut s) => { while let Some(tok) = toks.peek() { match tok.kind.clone() { diff --git a/tests/selectors.rs b/tests/selectors.rs index 4f6adf2..0705a7e 100644 --- a/tests/selectors.rs +++ b/tests/selectors.rs @@ -175,11 +175,16 @@ test!( "a {\n&--b {\n color: red;\n}\n}\n", "a--b {\n color: red;\n}\n" ); -// test!( -// bem_underscore_selector, -// "a {\n&__b {\n color: red;\n}\n}\n", -// "a__b {\n color: red;\n}\n" -// ); +test!( + bem_underscore_selector, + "a {\n&__b {\n color: red;\n}\n}\n", + "a__b {\n color: red;\n}\n" +); +test!( + selector_interpolation_addition, + "#{\"foo\" + \" bar\"}baz {color: red;}", + "foo barbaz {\n color: red;\n}\n" +); test!( selector_interpolation_start, "#{a}bc {\n color: red;\n}\n",