#1801 Generate a class as part of a DSL?

dobesv Fri 2 Mar 2012

I'm wondering if I can generate a new class as part of a DSL. I tried to output a ClosureDef but it seems like there's some preprocessing done to those to convert them into a class. Since a class is probably more useful for me, it seemed like a good idea - except for the fact that I'm not (as far as I know) in a legal location for a class definition to go in the code.

Any tips?

SlimerDude Fri 2 Mar 2012

Wousers! This sounds like real, in depth Fantom stuff requiring expert help. Unfortunately I fear you're (possibly?) in the wrong Time Zone for a quick response!

ivan Fri 2 Mar 2012

Hi dobesv

Yes, it is possible, basically you just access a compilation unit you are currently in and add new compiler::TypeDef to it. Some time ago I was very interested in Fantom DSLs and wrote an article – Exploring Fantom DSLs

brian Fri 2 Mar 2012

If you look thru compiler code you can see how it works:

  • in general synthetic classes use CompilerSupport.syntheticsUnit
  • use CompilerSupport.addTypeDef to ensure synthetic type is cleanly added

dobesv Fri 2 Mar 2012

Thanks, all. I think I'm going to try harder to return a closure which I think is what I really want in this case.

Login or Signup to reply.