diff --git a/src/common.rs b/src/common.rs index 927a4ba..d38e42b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -61,6 +61,8 @@ pub enum Symbol { QuestionMark, /// \ BackSlash, + /// ` + BackTick } impl Display for Symbol { @@ -95,6 +97,7 @@ impl Display for Symbol { Self::SingleQuote => write!(f, "'"), Self::QuestionMark => write!(f, "?"), Self::BackSlash => write!(f, "\\"), + Self::BackTick => write!(f, "`"), } } } @@ -133,6 +136,7 @@ impl TryFrom for Symbol { '\'' => Ok(Self::SingleQuote), '?' => Ok(Self::QuestionMark), '\\' => Ok(Self::BackSlash), + '`' => Ok(Self::BackTick), _ => Err("invalid symbol"), } } diff --git a/src/lexer.rs b/src/lexer.rs index c7e4901..d952464 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -133,7 +133,12 @@ impl<'a> Iterator for Lexer<'a> { '<' => symbol!(self, Lt), '>' => symbol!(self, Gt), '^' => symbol!(self, Xor), + '`' => symbol!(self, BackTick), '\0' => return None, + c if c.is_control() => { + self.buf.next(); + TokenKind::Error("Expected expression.".into()) + }, _ => self.lex_ident(), }; self.pos.next_char(); diff --git a/tests/error.rs b/tests/error.rs index 3ce0e79..44df98b 100644 --- a/tests/error.rs +++ b/tests/error.rs @@ -5,5 +5,9 @@ mod macros; error!( nothing_after_decimal, - "a {\n color: 1.;\n}\n", "Error: Expected digit." + "a {color: 1.;}", "Error: Expected digit." +); +error!( + ascii_control_character, + "a {color: ;}", "Error: Expected expression." ); diff --git a/tests/misc.rs b/tests/misc.rs index 151e296..745a119 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -47,12 +47,22 @@ test!( "a {\n color: red;\n}\n" ); test!( - utf8_ident_before, + utf8_ident_before_len, "a {\n color: length(😀red);\n}\n", "@charset \"UTF-8\";\na {\n color: 1;\n}\n" ); test!( - utf8_ident_after, + utf8_ident_before, + "a {\n color: 😀red;\n}\n", + "@charset \"UTF-8\";\na {\n color: 😀red;\n}\n" +); +test!( + utf8_ident_after_len, "a {\n color: length(red😁)\n}\n", "@charset \"UTF-8\";\na {\n color: 1;\n}\n" ); +test!( + utf8_ident_after, + "a {\n color: red😁\n}\n", + "@charset \"UTF-8\";\na {\n color: red😁;\n}\n" +);