Remove star-slash token

This commit is contained in:
Laurenz 2021-01-07 16:13:18 +01:00
parent 59d811aeba
commit 8275b186ba
3 changed files with 5 additions and 10 deletions

View File

@ -80,10 +80,7 @@ impl<'s> Parser<'s> {
let before = self.next_start; let before = self.next_start;
if let Some(found) = self.eat() { if let Some(found) = self.eat() {
let after = self.last_end; let after = self.last_end;
self.diag(match found { self.diag(error!(before .. after, "unexpected {}", found.name()));
Token::Invalid(_) => error!(before .. after, "invalid token"),
_ => error!(before .. after, "unexpected {}", found.name()),
});
} }
} }

View File

@ -68,7 +68,7 @@ impl<'s> Iterator for Tokens<'s> {
// Comments. // Comments.
'/' if self.s.eat_if('/') => self.line_comment(), '/' if self.s.eat_if('/') => self.line_comment(),
'/' if self.s.eat_if('*') => self.block_comment(), '/' if self.s.eat_if('*') => self.block_comment(),
'*' if self.s.eat_if('/') => Token::StarSlash, '*' if self.s.eat_if('/') => Token::Invalid(self.s.eaten_from(start)),
// Functions and blocks. // Functions and blocks.
'[' => Token::LeftBracket, '[' => Token::LeftBracket,
@ -770,8 +770,8 @@ mod tests {
#[test] #[test]
fn test_tokenize_invalid() { fn test_tokenize_invalid() {
// Test invalidly closed block comments. // Test invalidly closed block comments.
t!(Both: "*/" => StarSlash); t!(Both: "*/" => Token::Invalid("*/"));
t!(Both: "/**/*/" => BlockComment(""), StarSlash); t!(Both: "/**/*/" => BlockComment(""), Token::Invalid("*/"));
// Test invalid expressions. // Test invalid expressions.
t!(Header: r"\" => Invalid(r"\")); t!(Header: r"\" => Invalid(r"\"));

View File

@ -17,8 +17,6 @@ pub enum Token<'s> {
/// ///
/// The comment can contain nested block comments. /// The comment can contain nested block comments.
BlockComment(&'s str), BlockComment(&'s str),
/// An end of a block comment that was not started.
StarSlash,
/// A left bracket: `[`. /// A left bracket: `[`.
LeftBracket, LeftBracket,
@ -129,7 +127,6 @@ impl<'s> Token<'s> {
Self::LineComment(_) => "line comment", Self::LineComment(_) => "line comment",
Self::BlockComment(_) => "block comment", Self::BlockComment(_) => "block comment",
Self::StarSlash => "end of block comment",
Self::LeftBracket => "opening bracket", Self::LeftBracket => "opening bracket",
Self::RightBracket => "closing bracket", Self::RightBracket => "closing bracket",
@ -163,6 +160,7 @@ impl<'s> Token<'s> {
Self::Hex(_) => "hex value", Self::Hex(_) => "hex value",
Self::Str { .. } => "string", Self::Str { .. } => "string",
Self::Invalid("*/") => "end of block comment",
Self::Invalid(_) => "invalid token", Self::Invalid(_) => "invalid token",
} }
} }