Special Code String for mixins

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 15 07:12:57 PDT 2017


On Wednesday, 15 March 2017 at 13:50:28 UTC, Inquie wrote:
> I hate building code strings for string mixins as it's very 
> ugly and seems like a complete hack.

Me too, that's why I avoid doing it.

Check out my tips of the week here:
http://arsdnet.net/this-week-in-d/sep-20.html

and here:
http://arsdnet.net/this-week-in-d/2016-feb-21.html

for some ways I minimize them.

> How bout, instead, we have a special code string similar to a 
> multiline string that allows us to represent valid D code. The 
> compiler can then verify the string after compilation to make 
> sure it is valid D code(since it ultimately is a compile time 
> constant).

Are you familiar with D's `q{ ... }` literals? They are lexed 
though not parsed.

enum code1 = q{
    void happyCode = "Makes me @@s@@";
};

then you'd have to do the `.replace("@@s@@", whatever)` yourself 
on it though. They also do not allow unbalanced { }.


It is typed as string btw, no special type, just like if you used 
regular quotes, just looks nicer at the definition.



More information about the Digitalmars-d mailing list