www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Interpolation Expression Sequence (IES): Will Delimited Strings Ever

reply kdevel <kdevel vogtner.de> writes:
```
void main ()
{
    auto html = iq"_
<!DOCTYPE html>
<html>
    <head>
       <title>$(title)</title>
       <link rel = "stylesheet" href = "style.css">
    </head>
    <body>
_";
}
```

```
$  dmd iesdl.d
iesdl.d(3): Error: semicolon expected following auto declaration, 
not `"_\n<!DOCTYPE html>\n<html>\n   <head>\n      
<title>$(title)</title>\n      <link rel = "`
iesdl.d(8): Error: found `stylesheet` when expecting `;` 
following expression
iesdl.d(3):        expression: `"_\n<!DOCTYPE html>\n<html>\n   
<head>\n      <title>$(title)</title>\n      <link rel = "`
iesdl.d(8): Error: found `style` when expecting `;` following 
expression
iesdl.d(8):        expression: `" href = "`
iesdl.d(8): Error: found `">\n   </head>\n   <body>\n_"` when 
expecting `;` following expression
```
Aug 16
next sibling parent Dejan Lekic <dejan.lekic gmail.com> writes:
The answer is "yes, eventually". We were close with 
https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1027.md and Adam's
one which I like even more -
http://dpldocs.info/this-week-in-d/Blog.Posted_2019_05_13.html , but no
consensus reached...
Aug 16
prev sibling parent reply Dejan Lekic <dejan.lekic gmail.com> writes:
After talking to Adam on IRC, he pointed out that i`` works, so I 
was wrong apparently. The following works:

```
    string title = "D roX";
    auto html = i`
<!DOCTYPE html>
<html>
    <head>
       <title>$(title)</title>
       <link rel = "stylesheet" href = "style.css">
    </head>
    <body>
`;
```

iq{} does not work because what is inside is not valid D code. 
i"" would work if you escaped all the double-quotes which 
obviously you do not want to do, so i`` to the rescue!
Aug 16
next sibling parent kdevel <kdevel vogtner.de> writes:
On Friday, 16 August 2024 at 12:55:42 UTC, Dejan Lekic wrote:
 After talking to Adam on IRC, he pointed out that i`` works, so 
 I was wrong apparently. The following works:

 ```
    string title = "D roX";
    auto html = i`
 <!DOCTYPE html>
 <html>
    <head>
       <title>$(title)</title>
       <link rel = "stylesheet" href = "style.css">
    </head>
    <body>
 `;
 ```
There is a \n at the beginning of the string. That is the reason for using a delimited string [1] ``` auto html = q"DELIMTER <!DOCTYPE html> ... DELIMITER"; ```` [1] https://dlang.org/spec/lex.html#delimited_strings "The newline following the opening identifier is not part of the string [...]"
Aug 16
prev sibling parent reply kdevel <kdevel vogtner.de> writes:
On Friday, 16 August 2024 at 12:55:42 UTC, Dejan Lekic wrote:
 iq{} does not work because what is inside is not valid D code.
Valid D code is not required, valid D tokens suffice [2]. ``` auto html = iq{ <!DOCTYPE html> <html> <head> <title>$(title)</title> </head> <body> }; ``` Works (accidentally). [2] https://dlang.org/spec/lex.html#string_literals "Token strings open with the characters q{ and close with the token }. In between must be valid D tokens."
Aug 16
parent kdevel <kdevel vogtner.de> writes:
On Friday, 16 August 2024 at 13:49:58 UTC, kdevel wrote:
 [2] https://dlang.org/spec/lex.html#string_literals "Token 
 strings open with the characters q{ and close with the token }. 
 In between must be valid D tokens."
Sorry for replying to myself. But what constantly bothers me is imprecise language in the documentation. Let me quote from the page above: "Token strings open with the characters q{ and close with the token }. In between must be valid D tokens." Now from the example on that same page: ``` // q{ __EOF__ } // error // __EOF__ is not a token, it's end of file ``` __EOF__, however, /is/ a token, as we may read in [1] or [2]. [1] Issue 3695 - __EOF__ token not documented https://issues.dlang.org/show_bug.cgi?id=3695 »In "D 1.x -> D 2.x migration guide" and in "lex.html", the new token __EOF__ introduced in the D 2 is not documented. I think it should be explained in the "Special Tokens" section.« [2] Special Tokens https://dlang.org/spec/lex.html#specialtokens »__EOF__ tells the scanner to ignore everything after this token«
Aug 16