DWScript now supports multi-line strings, aka “heredoc”, using the same syntax as Prism/Oxygene, which involves double-quoting them, for instance:
s := "Lorem ipsum 'dolor' sit amet, consectetur adipiscing elit. Duis l'ipsum odio, pretium ""hendrerit"" varius sed, aliquet vitae elit. Sed eu libero nec nisl ""malesuada"" dignissim.";
is equivalent to
s := 'Lorem ipsum ''dolor'' sit amet, consectetur adipiscing elit.'#13#10 +'Duis l''ipsum odio, pretium "hendrerit" varius sed,'#13#10 +'aliquet vitae elit.'#13#10 +'Sed eu libero nec nisl "malesuada" dignissim.';
Which can be quite useful when you have multi-line string content, such as an SQL query, a long format string, a snippet of CSS/HTML/XML, etc.
Nate that if you’re using The SynEdit, the DWS highlighter has been updated and properly highlights those, you just need to get it from the SynEdit SVN.
It a slight cosmetic issue, shared AFAICT by other languages that implement “heredoc”, which is that if you don’t want to have spurious whitespace/tabs in the multi-line string, you basically have to break indentation.
Does any one knows a language which has a convenient “heredoc” syntax that would alleviate this issue?
autohotkey has the options LTRIM and JOIN
http://www.autohotkey.com/docs/Scripts.htm#continuation
Aligned heredoc:
From the document you linked to 🙂
@gabr
Well, they were aligned before I posted the comment 🙁
Check the Python section of the Here_document link.
@gabr
Pardon me, not Python but CoffeScript.
Strictly speaking, this is not a heredoc (because it doesn’t have a user-settable end-of-doc token), but a multiline string.
@gabr
dang! had missed CoffeeScript snippet! Looks like they always strip the left whitespace up the the indentation, and require the new line.
So single double-quote wouldn’t strip indentation (as in my snippet), but “double double-quote + newline” could preserve it. Looks quite good.
would be ‘my’#13#10′ string’, while
would be ‘my’#13#10’string’ ?
@Eric
If I’m guessing correctly what you typed before your whitespace was mangled, then yes 🙂
@gabr
Bloody HTML 😉 I’ve edited my and your snippet to unmangle things. Looking better?
@Eric
Much better, thanks!
Lua has nice feature to skip first CR/LF if multi line string starts with it:
@dmajkic
I believe that would be very nice extension. The only change in compiler logic is:
– If a quote is followed only by whitespace and newline, ignore this and start collecting the text with the next line.
Similar extension could be implemented for the terminating quote.
Those five would be then equivalent:
@gabr
Of course, formatting was again broken for the last example.
@gabr
Updated, I’ve also installed a plugin which allows placing code in <pre>, formatting should be preserved!
@Eric
Thanks again, Eric!
I love gabr’s last examples, I would use them a lot in queries!! what do you think Eric?
testing “pre”
tag
can
remove
this
ummm, my formatting wasn’t preserved for some reasons, I had a lot of spaces, should I have used ” ” in stead of ” ” <- space?
@Dorin Duminica
You should use inferior & superior signs