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

Line continuation character inside string macros does not continue lines #55885

Open
thchr opened this issue Sep 26, 2024 · 5 comments
Open

Line continuation character inside string macros does not continue lines #55885

thchr opened this issue Sep 26, 2024 · 5 comments
Labels
strings "Strings!"

Comments

@thchr
Copy link
Contributor

thchr commented Sep 26, 2024

The @lazy_str macro behaves differently from ordinary strings when using the line continuation character \:

lstr = lazy"hello \
       world"       # == "hello \\\n       world"
str  = "hello \
       world"       # == "hello world"

Apart from interpreting the line-continuation character as a "raw" backslash (and consequently also inserting a line-break), lazy"..." also doesn't ignore the white-space on the following line. This seems unintended and undesirable.

@jishnub jishnub added the strings "Strings!" label Sep 26, 2024
@barucden
Copy link
Contributor

It's not specific to @lazy_str:

julia> macro foo_str(s)
           show(s)
       end
@foo_str (macro with 1 method)

julia> foo"hello \
           world"
"hello \\\n    world"

@thchr thchr changed the title Line continuation character inside @lazy_str does not continue lines Line continuation character inside string macros does not continue lines Sep 26, 2024
@thchr
Copy link
Contributor Author

thchr commented Sep 26, 2024

Good catch; updated title to reflect this.

@vtjnash
Copy link
Member

vtjnash commented Sep 26, 2024

There is no line continuation character for string macros, so that title isn't quite right either, as something that doesn't exist cannot be blamed for not working. The main thing this may want is to replace the content of lazy string with the content mangled according to calling str = unescape_string(escape_raw_string(str)). This is slightly breaking, so we cannot necessarily do it for existing macros, but new ones (e.g. styled"") implements this transform to follow the user's typical expectations.

@thchr
Copy link
Contributor Author

thchr commented Sep 26, 2024

Makes sense; feel free to update title to something more precise.

@thchr
Copy link
Contributor Author

thchr commented Sep 26, 2024

It seems unlikely that relatively recent string macros like lazy"" would incur real breakage for such a change though. On other hand, it probably wouldn't be nice to change raw"" to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!"
Projects
None yet
Development

No branches or pull requests

4 participants