Bug 24015 – C#-style indented delimited strings

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-06-26T16:28:45Z
Last change time
2024-12-13T19:29:54Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#20306 →

Comments

Comment #0 by qs.il.paperinik — 2023-06-26T16:28:45Z
https://dlang.org/spec/lex.html#delimited_strings allows identifier-delimited strings like ``` q"EOS This is a multi-line heredoc string EOS" ``` However, that “The closing identifier must be placed on its own line at the leftmost column” is annoying and ugly in code w.r.t. indentation. For example: ```d void f() { string str = q"EOS This is a multi-line heredoc string EOS"; } ``` C# has triple-quote strings that are similar to D’s identifier-delimited strings as if `""` were the identifier, however, C# allows the string to be in one line and if it is not, the whitespace between the last newline and the closing """ is not considered part of the string – and, of course, must be present at the beginning of every line of the string. For the sake of readability, D should have something similar: If the sequence `q"` *end-of-string-identifier* *newline* is followed by whitespace (a sequence of whitespace characters), the whitespace is repeated on every line up until a line consists of the whitespace and the *end-of-string-identifier* `"` string terminator, that is considered a string literal. The line-initial whitespace is not part of the literal. E.g.: ```d void f() { string str = q"EOS This is a multi-line heredoc string EOS"; assert(str == "This\nis a multi-line\nheredoc string\n"); } ``` Theoretically, this is a breaking change, but it will be very unlikely that the string termination sequence will be anywhere in the string, let alone after whitespace that is repeated on every line before. Alternatively, D can go “full C#” and just implement `"""` delimited strings with the exact same semantics as C#: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string
Comment #1 by robert.schadek — 2024-12-13T19:29:54Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20306 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB