From 67091115db6f22dea3d3f7317ae94580a9cf1ce6 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Thu, 21 May 2020 12:06:42 -0400 Subject: [PATCH] better handle - at the start of idents --- src/stylesheet.rs | 2 +- src/utils/peek_until.rs | 3 +++ src/utils/strings.rs | 6 ++++++ tests/error.rs | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/stylesheet.rs b/src/stylesheet.rs index 717f9a1..540502d 100644 --- a/src/stylesheet.rs +++ b/src/stylesheet.rs @@ -295,7 +295,7 @@ impl<'a> StyleSheetParser<'a> { c if c.is_control() => { return Err(("expected selector.", self.lexer.next().unwrap().pos()).into()); } - ',' | '!' => { + ',' | '!' | '{' => { return Err(("expected \"{\".", self.lexer.next().unwrap().pos()).into()); } '`' => { diff --git a/src/utils/peek_until.rs b/src/utils/peek_until.rs index eaedc76..d9a38af 100644 --- a/src/utils/peek_until.rs +++ b/src/utils/peek_until.rs @@ -166,6 +166,9 @@ pub(crate) fn peek_ident_no_interpolation>( if toks.peek().unwrap().kind == '-' { toks.peek_forward(1); text.push('-'); + if toks.peek().is_none() { + return Ok(Spanned { node: text, span }); + } if toks.peek().unwrap().kind == '-' { toks.peek_forward(1); text.push('-'); diff --git a/src/utils/strings.rs b/src/utils/strings.rs index f6abfa2..b0b7116 100644 --- a/src/utils/strings.rs +++ b/src/utils/strings.rs @@ -179,6 +179,9 @@ pub(crate) fn eat_ident>( if toks.peek().unwrap().kind == '-' { toks.next(); text.push('-'); + if toks.peek().is_none() { + return Ok(Spanned { node: text, span }); + } if toks.peek().unwrap().kind == '-' { toks.next(); text.push('-'); @@ -235,6 +238,9 @@ pub(crate) fn eat_ident_no_interpolation>( if toks.peek().unwrap().kind == '-' { toks.next(); text.push('-'); + if toks.peek().is_none() { + return Ok(Spanned { node: text, span }); + } if toks.peek().unwrap().kind == '-' { toks.next(); text.push('-'); diff --git a/tests/error.rs b/tests/error.rs index e9707f6..bc4fdf8 100644 --- a/tests/error.rs +++ b/tests/error.rs @@ -85,6 +85,10 @@ error!( error!(toplevel_comma, "a {},", "Error: expected \"{\"."); error!(toplevel_exclamation, "! {}", "Error: expected \"{\"."); error!(toplevel_backtick, "` {}", "Error: expected selector."); +error!( + toplevel_open_curly_brace, + "{ {color: red;}", "Error: expected \"{\"." +); error!( backtick_in_value, "a {color:`red;}", "Error: Expected expression." @@ -93,3 +97,15 @@ error!( comma_begins_value, "a {color:,red;}", "Error: Expected expression." ); +error!( + nothing_after_hyphen, + "a {-}", "Error: Expected \":\"." +); +error!( + nothing_after_hyphen_variable, + "a {$-", "Error: expected \":\"." +); +error!( + closing_brace_after_hyphen_variable, + "a {$-}", "Error: Expected identifier." +);