Skip to content

string literals: disallow backslash before non-escapes #21284

Closed
@StefanKarpinski

Description

See: http://stackoverflow.com/questions/43114125/how-to-replace-string-literals-back-front-slashes-in-julia. There are a couple of issues here:

  1. 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.

  2. 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.

Metadata

Assignees

No one assigned

    Labels

    breakingThis change will break codehelp wantedIndicates that a maintainer wants help on an issue or pull requestneeds decisionA decision on this change is neededparserLanguage parsing and surface syntaxstrings"Strings!"

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions