E0028: invalid string escape

View source

A backslash in a string literal starts an escape sequence.

A backslash in a string literal starts an escape sequence. The valid escapes are \n (line feed), \t (tab), \r (carriage return), \\ (a backslash), \" (a double quote) and \u{H...}, where 1 to 6 hexadecimal digits name a Unicode scalar value, which is stored as its UTF-8 bytes. A Unicode scalar value is any value from U+0001 to U+10FFFF except the surrogates U+D800 to U+DFFF. The lexer reports this error for any other character after a backslash, such as \q, and for a \u escape that has no braces, an empty or unterminated {}, more than 6 digits, a digit that is not hexadecimal, or a value that is not a Unicode scalar value. \0 and \u{0} are also this error: a string literal cannot hold the NUL character, because a String ends at its first NUL byte. For the same reason a NUL character (U+0000) written directly between the quotes is this error too, with the same message; the error points at that one character, which is invisible in the source. The message gives the escape as it is written and lists the valid escapes, and the error points at the escape sequence only, not at the whole literal. A backslash that ends the line or the file is not an escape: the literal is unterminated (E0002). Docstrings (""") are raw text and take no escapes (ADR-0137).

Example

actus
verb main() {
    println(string: "one\qtwo");
}

Fix

Write a valid escape. To write a backslash itself, write \\.

actus
verb main() {
    println(string: "one\ttwo");
}

Run actus explain E0028 in your terminal to read this entry offline. Browse Lexer & parser or all error codes.