www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - __traits and string mixins

reply =?UTF-8?Q?Christian_K=c3=b6stlin?= <christian.koestlin gmail.com> writes:
Hi,

I started an experiment with the informations that are available for 
compile time reflection.

What I wanted to create is a thor like cli parser library, that forces 
you to encapsulate your programs into subclasses of Dli. The commands
and options, that are understood by the generated cli are taken from the 
members, that have to be enhanced with UCA's. The __traits facility is 
used to generate from those a string mixin, that also has to be added to 
your class. A sample usage would look like this:

class Git : Dli {
    Option string verbose;

    Task void helloWorld(string option1, string option2) {
     ...
     your code here
     ...
   }
   mixin(createDli!(Git));
}

this program should be able to understand:

./git --verbose helloWorld --option1=pretty --option2=whatever

When I created this stuff the __traits stuff got me thinking, because I 
iterate e.g. allMembers of a class, but the result of this code is mixed 
in again into the class (and creates new members on the way).

So how exactly is this done compiler wise?

Another question that came up for me is: would it not be awesome, if the 
whole AST would be available in traits? The facilities as they are, are 
already a little bit more powerful than e.g. java reflection, because 
you can e.g. get to the name of parameters of method.

thanks for your input,

christian

p.s.: if you are interested in a very rough first version of the code or 
if you have enhancements for it, please have a look at: 
https://github.com/gizmomogwai/dli
Dec 03 2015
parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Thursday, 3 December 2015 at 13:36:16 UTC, Christian Köstlin 
wrote:
 Hi,

 I started an experiment with the informations that are 
 available for compile time reflection.

 [...]
I think CyberShadow (aka Vladimir Panteleev) has done something similar to this http://blog.thecybershadow.net/2014/08/05/ae-utils-funopt/
Dec 04 2015
parent =?UTF-8?Q?Christian_K=c3=b6stlin?= <christian.koestlin gmail.com> writes:
On 04/12/15 21:49, Nicholas Wilson wrote:
 On Thursday, 3 December 2015 at 13:36:16 UTC, Christian Köstlin wrote:
 Hi,

 I started an experiment with the informations that are available for
 compile time reflection.

 [...]
I think CyberShadow (aka Vladimir Panteleev) has done something similar to this http://blog.thecybershadow.net/2014/08/05/ae-utils-funopt/
Thanks for the pointer! funopt really does look nice and it looks also finished! regards, christian
Dec 04 2015