Mixin template evaluated to string can convert to string mixin expression implicitly

Alex_Dovhal alex_dovhal at yahoo.com
Fri Jun 24 15:16:46 PDT 2011


"Timon Gehr" <timon.gehr at gmx.ch> wrote:
> My question could not possibly be answered with 'yes', actually I was 
> interested
> in what functionality your library would provide for the end user.
> You answered the question "Would your library be capable of building an 
> AST?".

Sorry for ambiguity, "yes" was answer for
    > Macros operate on ASTs, not strings.
Yes I plan to build AST, but for every different DSEL/macro type, different 
AST is used.

>> /*AST, here string[]*/ string[] parseAST_1(string arg)
>> {
>>     //do something. e.g.
>>     return [arg];
>> }
> How do you want to store your AST in a string[]? (Yes, it works, if you 
> want some
> really hacky, ugly and overlong code.)

It's just simplest example which works in CTFE, sure AST builder should be 
class-tree not array of strings.

>> int main()
>> {
>>     assert(mixin(macroFunct!q{123})==123);
>>     assert(! (mixin(macroFunct!q{321})==322));
>>
>>     return 0;
>> }
>
> You did not fill out the function bodies because that would be a PITA and 
> some
> n*1000 lines long, right?
> Lexing and parsing code should be the compiler's business.

For library yes, but end user must have simple interface. Sorry for not 
giving more concrete info, it's steel in too early stage.

> You want to use a compiler to interpret code that then parses other code 
> into an
> AST, that is then mutated and then converted back to a string, just that 
> the
> compiler's native parser can parse it again.

Compiler can't parse every DSEL AST. Even not everywhere full AST in needed! 
For most task's it's enoungh to parse:
 * comments
 * strings
 * matching bracket blocks (to find one comma separator in  fcn!q{a, (b, 
c)+d}  )
 * comma, colon and semicolon sepatated items (fcn!q{name1: val1, name2: 
val2 ; otherBlock})
to get extended C macros

> The fact that it could be made to work does not mean it is a good idea. :)

But it's good for hobby project to try D.




More information about the Digitalmars-d mailing list