Lyricdev
GitHub

LYR-LEX0007

a malformed escape sequence

error · spec 01-lexical

A string, character or f-string holds a \ that starts no escape (\q), a \x without two hex digits, or a \u that is not \u{…} with one to eight hex digits naming a Unicode scalar value (at most 10FFFF, no surrogate).

Explanation

The escapes are \n, \t, \r, \0, \\, \", \' and \u{…}, which names a character by its scalar value; \xNN writes a byte and belongs to a byte string. Any other letter after the backslash is no escape.

Write one of the escapes, or a raw string r"…" when the backslash is meant as itself.

Wrong

fn main(): void {
    let s = "tab\q";
    let _ = s;
}
fn main(): void {
    let s = "tab\t";
    let _ = s;
}