What are delimited string, heredoc and D token strings?

Pierre Rouleau prouleau001 at gmail.com
Sun Jun 27 08:15:52 PDT 2010


On 27/06/10 9:52 AM, Simen kjaeraas wrote:
> Pierre Rouleau <prouleau001 at gmail.com> wrote:
>
>> Hi all,
>>
>> The D2.0 lexical page describes delimited string and token string
>> literals. Is there any example of how these are used and why, somewhere?
>
> Token strings are added for the specific use case of string mixins[1].
> They must contain valid D code.
>
> mixin( q{ a = b; } ); // Works.
> mixin( q{ this is nonsense, I tell you! } ); // Does not work.
>
> Editors may syntax-highlight token strings as if it were normal code.
> They often do, by virtue of having no idea that it is indeed a string.
>
>
> Delimited strings and heredoc strings exist for simplicity of adding long
> strings to the source.
>
> q"EOS
> Heredoc strings allow you to add long string literals to your code.
> They also let you embed "quotes" 'of' `various` ´kinds´ without escaping
> them.
> EOS"
>
> q"(Delimited strings are much the same as "heredoc" strings, but somewhat
> more succinct, by not using a whole identifier for terminators. They are
> thus not as suited for long texts.)"
>
>
> [1]: http://digitalmars.com/d/2.0/statement.html#MixinStatement
> also,
> http://digitalmars.com/d/2.0/expression.html#MixinExpression
> http://digitalmars.com/d/2.0/module.html#MixinDeclaration

Thanks for this clear explanation, Simen.

I was wondering if D had the equivalnt of Python's triple quote string 
literals and it does: the delimited string serves the same purpose.  Great!

-- Pierre


More information about the Digitalmars-d-learn mailing list