string literals: disallow backslash before non-escapes #21284
Description
See: http://stackoverflow.com/questions/43114125/how-to-replace-string-literals-back-front-slashes-in-julia. There are a couple of issues here:
-
Since Python behaves differently here for backslash followed by non-escapes, allowing these sequences can cause confusion for Python programmers. It would be better to give an error when a user writes something like
"ab\c"
telling them to write"ab\\c"
instead if they wanted a literal backslash or to write"abc"
if they don't want a literal backslash. -
If
"ab\c"
is an error, that leaves the syntax open in the future for new meanings, giving us room for extensibility. This does not sacrifice any expressiveness since writing\c
for non-control characters is otherwise completely useless. For example, we could then introduce something like the syntax"foo\(bar)baz"
that has previously been proposed for interpolation (this is Swift's interpolation syntax) without fear of breaking anyone's code.