String mixin syntax sugar
Mantis
mail.mantis.88 at gmail.com
Tue Mar 20 11:25:44 PDT 2012
Hello,
since people discussed a lot about user-defined attributes recently,
I've been thinking about a way to implement it with a string mixins. The
problem with them is their syntax - it's far from what we want to use in
everyday job. I understand, they should be easily distinguished at use
site, but perhaps this may be accomplished in other ways as well. My
idea is to translate this kind of statements:
# identifier statement
into this:
mixin( identifier( q{ statement } ) );
where an identifier is a, possibly templated, function that accepts one
string argument and returns a string. Here are some possible use cases:
#serialize int a; // marked to be serializable
#serialize!not int b; // -.- non-serializable
#readonly float c; // generate trivial private setter and public getter
#handles!Events.Foo void handler(); // event handler
#attribute!"Foo" void foo(); // function with additional compile-time info
Most of these examples require some D parser, but, since it is planned
to add parser-generation into Phobos, this shouldn't be a problem.
What do you think, does it have some value for the language, and, if
yes, is it possible to implement?
More information about the Digitalmars-d
mailing list