allow variables named to and through in @for

This commit is contained in:
Connor Skees 2020-07-02 16:06:34 -04:00
parent e9f2cdbe4d
commit 125c85a69c
2 changed files with 28 additions and 5 deletions

View File

@ -631,17 +631,29 @@ impl<'a> Parser<'a> {
match ident.node.to_ascii_lowercase().as_str() {
"through" => {
through = 1;
// todo: it should take more if there were escapes
self.toks.take(7).for_each(drop);
self.toks.truncate_iterator_to_cursor();
break;
}
"to" => {
// todo: it should take more if there were escapes
self.toks.take(2).for_each(drop);
self.toks.truncate_iterator_to_cursor();
break;
}
_ => {
return Err(("Invalid flag name.", ident.span).into());
from_toks.push(tok);
self.toks.next();
self.toks.reset_cursor();
}
}
}
'$' => {
from_toks.push(tok);
self.toks.next();
while let Some(tok) = self.toks.peek() {
if matches!(tok.kind, '0'..='9' | 'a'..='z' | 'A'..='Z' | '\\' | '-' | '_')
{
from_toks.push(self.toks.next().unwrap());
} else {
break;
}
}
}

View File

@ -68,3 +68,14 @@ test!(
"@for $i from -1 to -3 {\n a {\n color: red;\n }\n}\n",
"a {\n color: red;\n}\n\na {\n color: red;\n}\n"
);
test!(
variable_named_to_as_value,
"$to: 0;
@for $i from $to to 1 {
a {
color: red;
}
}",
"a {\n color: red;\n}\n"
);