DIP 50 - AST macros

luka8088 luka8088 at owave.net
Fri Nov 22 15:43:26 PST 2013


On 22.11.2013. 11:17, Jacob Carlborg wrote:
> On 2013-11-22 10:27, luka8088 wrote:
> 
>> Um, my it's suppose to be the same as <[ ... ]> but I liked t{ ... }
>> syntax better as it looked more consistent with what D already has. But
>> I should have used <[ ... ]> , my mistake sorry.
> 
> I thought you argued that the t{ } need to contain semantically valid code?
> 

Yes. I still do. And I think that <[ ... ]> should contain semantically
valid code. In my opinion, if you wish to be able to write anything
else, the way to go would be: write it using q{ ... }, parse it
yourself, build a valid D AST yourself, give D AST to the compiler using
mixin().

Currently mixin() only accepts a string that contains a valid D code. So
if you have a custom parser for your DSL you need to generate a D code
from that DSL and then pass it to the compiler using mixin() in order
for the compiler to parse it again. Double parsing could be skipped if
mixin() would accept already built D AST and on the other hand parsing
DSL and building D AST yourself would allow maximum flexibility.


More information about the Digitalmars-d mailing list