From 125c85a69c3feb71ec3de531babadfc3d679facb Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Thu, 2 Jul 2020 16:06:34 -0400 Subject: [PATCH] allow variables named `to` and `through` in `@for` --- src/parse/mod.rs | 22 +++++++++++++++++----- tests/for.rs | 11 +++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/parse/mod.rs b/src/parse/mod.rs index cf9a38a..ab8b3d7 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -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; } } } diff --git a/tests/for.rs b/tests/for.rs index 8efa921..b47fc07 100644 --- a/tests/for.rs +++ b/tests/for.rs @@ -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" +);