Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow escaping newlines with \ inside strings #40753

Merged
merged 7 commits into from
Jun 3, 2021

Conversation

simeonschaub
Copy link
Member

This allows the use of \ in front of newlines inside
non-raw/non-custom string or command literals as a line continuation
character, so the following newline is ignored. This way, long strings
without any newlines in them don't have to be written in a single line
or be broken up. I think we might also want to use this to improve the
printing of long strings in the REPL by printing them as multiline
strings, making use of \ for long lines if necessary, but that can be
discussed separately.

The command literal part is technically breaking, but the current
behavior is probably unintuitive enough that this can be considered a
minor change. For string literals, this should be entirely non-breaking
since a single \ before a newline currently throws a parsing error.

closes #37728

@simeonschaub simeonschaub added parser Language parsing and surface syntax strings "Strings!" needs news A NEWS entry is required for this change minor change Marginal behavior change acceptable for a minor release labels May 8, 2021
@simeonschaub simeonschaub force-pushed the sds/string_line_continuation branch 2 times, most recently from 6f454e8 to d7263a1 Compare May 8, 2021 23:12
@simeonschaub simeonschaub force-pushed the sds/string_line_continuation branch from d7263a1 to 8600586 Compare May 9, 2021 18:22
src/julia-parser.scm Outdated Show resolved Hide resolved
src/julia-parser.scm Outdated Show resolved Hide resolved
@simeonschaub
Copy link
Member Author

Bump. Is this good to go?

@simeonschaub simeonschaub added this to the 1.7 milestone May 26, 2021
This allows the use of `\` in front of newlines inside
non-raw/non-custom string or command literals as a line continuation
character, so the following newline is ignored. This way, long strings
without any newlines in them don't have to be written in a single line
or be broken up. I think we might also want to use this to improve the
printing of long strings in the REPL by printing them as multiline
strings, making use of `\` for long lines if necessary, but that can be
discussed separately.

The command literal part is technically breaking, but the current
behavior is probably unintuitive enough that this can be considered a
minor change. For string literals, this should be entirely non-breaking
since a single `\` before a newline currently throws a parsing error.

closes #37728
@simeonschaub simeonschaub removed the needs news A NEWS entry is required for this change label May 29, 2021
base/shell.jl Outdated Show resolved Hide resolved
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge, with one minor correction to cmd handling

simeonschaub and others added 2 commits June 1, 2021 09:58
@simeonschaub
Copy link
Member Author

Failures are definitely unrelated, but I would feel more comfortable if we could verify that this passes on Windows as well, to make sure we don't introduce any platform-related newline issues.

NEWS.md Outdated
@@ -16,6 +16,9 @@ New language features
in `[A; B]` has always described concatenating along the first dimension (vertically), now two
semicolons `[A;; B]` do so in the second dimension (horizontally), three semicolons `;;;` in the
third, and so on. ([#33697])
* A backslash (`\`) before a newline inside a string literal now escapes the newline while also
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's unclear what "escapes" means here; sometimes escaping a character means including it, e.g. "\"".

There are also manual sections on string literals that should mention this.

@JeffBezanson JeffBezanson added the needs docs Documentation for this change is required label Jun 1, 2021
@StefanKarpinski
Copy link
Member

Let me voice a concern about this: if we do this we cannot ever allow backslash escaping spaces or tabs because if we do that then with this feature you would be visually unable to tell what a program does — you would have to check to make sure that what's after an apparently trailing backslash is actually a newline and not some invisible trailing whitespace characters before the newline. Yes, whether those trailing spaces are there or not in a quote affects the program behavior either way in the sense that anything inside of quotes like that affects program behavior, but I think that this would mean that invisible trailing whitespace might affect program behavior in a much more significant way than merely being there. Currently we error if you try to escape a space or a tab in a string literal, so we're ok as this stands, but I just wanted to point it out.

@vtjnash
Copy link
Member

vtjnash commented Jun 3, 2021

Markdown assigns meaning to trailing \ and/or significant trailing whitespaces, but I don't think we're likely to adopt that (there is a rejected issue about adding it)

@vtjnash vtjnash merged commit d5f1dca into master Jun 3, 2021
@vtjnash vtjnash deleted the sds/string_line_continuation branch June 3, 2021 14:55
shirodkara pushed a commit to shirodkara/julia that referenced this pull request Jun 9, 2021
This allows the use of `\` in front of newlines inside
non-raw/non-custom string or command literals as a line continuation
character, so the following newline is ignored. This way, long strings
without any newlines in them don't have to be written in a single line
or be broken up. I think we might also want to use this to improve the
printing of long strings in the REPL by printing them as multiline
strings, making use of `\` for long lines if necessary, but that can be
discussed separately.

The command literal part is technically breaking, but the current
behavior is probably unintuitive enough that this can be considered a
minor change. For string literals, this should be entirely non-breaking
since a single `\` before a newline currently throws a parsing error.

closes JuliaLang#37728
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
This allows the use of `\` in front of newlines inside
non-raw/non-custom string or command literals as a line continuation
character, so the following newline is ignored. This way, long strings
without any newlines in them don't have to be written in a single line
or be broken up. I think we might also want to use this to improve the
printing of long strings in the REPL by printing them as multiline
strings, making use of `\` for long lines if necessary, but that can be
discussed separately.

The command literal part is technically breaking, but the current
behavior is probably unintuitive enough that this can be considered a
minor change. For string literals, this should be entirely non-breaking
since a single `\` before a newline currently throws a parsing error.

closes JuliaLang#37728
@simeonschaub simeonschaub removed the needs docs Documentation for this change is required label Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor change Marginal behavior change acceptable for a minor release parser Language parsing and surface syntax strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

backslash in cmd literal escapes newline
4 participants