DIP 50 - AST macros
Dmitry Olshansky
dmitry.olsh at gmail.com
Tue Nov 12 12:55:46 PST 2013
12-Nov-2013 21:03, Dicebot пишет:
> On Tuesday, 12 November 2013 at 16:54:19 UTC, Andrei Alexandrescu wrote:
>> I don't see how AST reflection is needed for generating correct D code
>> from an SQL expression. Dmitry did exactly that with ctRegex. Please
>> illuminate.
>
> Other way around. Generating arbitrary output (including but not limited
> to SQL expressions) from D code. As I have already mentioned, it is the
> very same thing we do now with __traits and UDA's but not limited to
> only declarations.
Actually I couldn't shake off the feeling that macros are just CTFE
functions on Ast objects. How objects are created and converted back to
source code is a separate question.
If we just had:
//this would invoke compiler's parser at CTFE
auto ast = "x = y;".astof
and have it work at CTFE to return sensible AST (a big if btw).
And then (after some manipulations):
ast.toString() //get back a string of D code
It may help code generation of D --> DSL.
Alternatively one can implement D parser that works at CTFE and watch it
crawl :)
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list