You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
String literals have no escape sequences, so some strings can't be written at all:
const Q: string = "say \"hi\"" // doesn't parse: a string can't contain `"`
const N: string = "a\nb" // builds, as a backslash and an `n`, not a newline
StringLiteral is "([^"]*)", kept as written. Generators already escape what they're given ("a\nb" in a schema becomes "a\\nb" in Rust and TypeScript), so values survive; there's just no way to write a quote, a newline or a non-printing character.
Proposal: the escapes most languages share:
Escape
Character
\"
"
\\
\
\n, \r, \t
newline, carriage return, tab
\0
NUL
\u{1F600}
any Unicode scalar value, 1 to 6 hex digits (no surrogates)
Any other backslash sequence is a build error, so a future escape can be added without changing what an existing string means. The same rules hold in f-strings (error messages, validator messages), alongside {{ and }}.
Compatibility: a constant or default written today with \n, \t, \0 or \\ changes value. That's acceptable before 1.0; version comparison reports each changed constant as it does any value change. Other backslashes become errors, pointing at the escape to use.
Activity