Properly interpolate values coming from variables

This commit is contained in:
ConnorSkees 2020-01-26 18:43:07 -05:00
parent 1761af0a01
commit c7efbc7e05
3 changed files with 12 additions and 5 deletions

View File

@ -1,5 +1,7 @@
use crate::common::{Scope, Symbol}; use crate::common::{Scope, Symbol};
use crate::utils::{devour_whitespace, devour_whitespace_or_comment, eat_interpolation, IsWhitespace}; use crate::utils::{
devour_whitespace, devour_whitespace_or_comment, eat_interpolation, IsWhitespace,
};
use crate::{Token, TokenKind}; use crate::{Token, TokenKind};
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use std::iter::Peekable; use std::iter::Peekable;

View File

@ -1,4 +1,5 @@
use crate::common::{Pos, Symbol}; use crate::common::{Pos, Symbol};
use crate::lexer::Lexer;
use crate::value::Value; use crate::value::Value;
use crate::{Scope, Token, TokenKind}; use crate::{Scope, Token, TokenKind};
use std::iter::{Iterator, Peekable}; use std::iter::{Iterator, Peekable};
@ -50,10 +51,9 @@ pub(crate) fn eat_interpolation<I: Iterator<Item = Token>>(
TokenKind::Symbol(Symbol::OpenCurlyBrace) => { TokenKind::Symbol(Symbol::OpenCurlyBrace) => {
todo!("invalid character in interpolation") todo!("invalid character in interpolation")
} }
TokenKind::Variable(ref v) => val.push(Token { TokenKind::Variable(ref v) => val.extend(
pos: tok.pos, Lexer::new(&scope.vars.get(v).unwrap().to_string()).collect::<Vec<Token>>(),
kind: TokenKind::Ident(scope.vars.get(v).unwrap().to_string()), ),
}),
TokenKind::Interpolation => val.extend(eat_interpolation(tokens, scope)), TokenKind::Interpolation => val.extend(eat_interpolation(tokens, scope)),
_ => val.push(tok), _ => val.push(tok),
} }

View File

@ -299,6 +299,11 @@ mod test_selectors {
"a /* foo */ b {\n color: red;\n}\n", "a /* foo */ b {\n color: red;\n}\n",
"a b {\n color: red;\n}\n" "a b {\n color: red;\n}\n"
); );
test!(
interpolates_comma,
"$x: oo, ba;\nf#{$x}r {\n baz {\n color: red;\n }\n}\n",
"foo baz, bar baz {\n color: red;\n}\n"
);
} }
#[cfg(test)] #[cfg(test)]