refactor parsing of quoted strings with interpolation containing strings
This commit is contained in:
parent
7579a6e9b5
commit
64e2632de4
32
src/utils.rs
32
src/utils.rs
@ -164,40 +164,28 @@ pub(crate) fn read_until_closing_quote<I: Iterator<Item = Token>>(
|
||||
toks: &mut Peekable<I>,
|
||||
q: char,
|
||||
) -> Vec<Token> {
|
||||
let mut is_escaped = false;
|
||||
let mut t = Vec::new();
|
||||
for tok in toks {
|
||||
while let Some(tok) = toks.next() {
|
||||
match tok.kind {
|
||||
'"' if !is_escaped && q == '"' => {
|
||||
'"' if q == '"' => {
|
||||
t.push(tok);
|
||||
break;
|
||||
}
|
||||
'"' if is_escaped => {
|
||||
t.push(tok);
|
||||
is_escaped = false;
|
||||
continue;
|
||||
}
|
||||
'\'' if !is_escaped && q == '\'' => {
|
||||
'\'' if q == '\'' => {
|
||||
t.push(tok);
|
||||
break;
|
||||
}
|
||||
'\'' if is_escaped => {
|
||||
t.push(tok);
|
||||
is_escaped = false;
|
||||
continue;
|
||||
}
|
||||
'\\' if !is_escaped => {
|
||||
t.push(tok);
|
||||
is_escaped = true
|
||||
}
|
||||
'\\' => {
|
||||
is_escaped = false;
|
||||
t.push(tok);
|
||||
continue;
|
||||
t.push(toks.next().unwrap());
|
||||
}
|
||||
_ if is_escaped => {
|
||||
is_escaped = false;
|
||||
'#' => {
|
||||
t.push(tok);
|
||||
let next = toks.peek().unwrap();
|
||||
if next.kind == '{' {
|
||||
t.push(toks.next().unwrap());
|
||||
t.append(&mut read_until_closing_curly_brace(toks));
|
||||
}
|
||||
}
|
||||
_ => t.push(tok),
|
||||
}
|
||||
|
@ -33,3 +33,8 @@ test!(
|
||||
"a {\n color: '#{foo}';\n}\n",
|
||||
"a {\n color: \"foo\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
double_quotes_inside_double_quoted_string,
|
||||
"a {\n color: #{\"#{'\"'}\"};\n}\n",
|
||||
"a {\n color: \";\n}\n"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user