Closed
Description
When using logos, I get the following broken syntax highlighting:
Original source for replication purposes:
#[derive(Debug, Clone, Logos)]
enum Quoted<'source> {
#[regex(r#"[^\\"']+"#)]
Text(&'source str),
#[token("\\")]
StartEscape,
#[token("\'", |_| Quote::Single)]
#[token("\"", |_| Quote::Double)]
End(Quote),
#[error]
Error,
}
#[derive(Debug, Clone, Logos)]
enum Escape {
#[token("\\", |_| '\\')]
#[token("n", |_| '\n')]
#[token("r", |_| '\r')]
#[token("t", |_| '\t')]
#[token("0", |_| '\0')]
#[token("\'", |_| '\'')]
#[token("\"", |_| '\"')]
Single(char),
#[token("u")]
StartUnicodeEscape,
#[token("x")]
StartAsciiEscape,
#[error]
Error,
}
#[derive(Debug, Clone, Logos)]
enum UnicodeEscape<'source> {
#[regex(r"\{[0-9a-fA-F]*\}", |lexer| &lexer.slice()[1..(lexer.slice().len() - 1)])]
CharCode(&'source str),
#[token("\'", |_| Quote::Single)]
#[token("\"", |_| Quote::Double)]
End(Quote),
#[error]
Error,
}
A workaround (suggested by @Kixiron and seen in the wild in Crunch) is to add // workaround highlighting: "
to the offending lines:
#[derive(Debug, Copy, Clone, PartialEq)]
enum Quote {
Single,
@@ -33,7 +61,7 @@ enum QuotedLiteral {
#[derive(Debug, Clone, Logos)]
enum Quoted<'source> {
- #[regex(r#"[^\\"']+"#)]
+ #[regex(r#"[^\\"']+"#)] // workaround highlighting: "
Text(&'source str),
#[token("\\")]
StartEscape,
@@ -53,7 +81,7 @@ enum Escape {
#[token("t", |_| '\t')]
#[token("0", |_| '\0')]
#[token("\'", |_| '\'')]
- #[token("\"", |_| '\"')]
+ #[token("\"", |_| '\"')] // workaround highlighting: "
Single(char),
#[token("u")]
StartUnicodeEscape,