Embedding a DSL into D source

Bill Baxter wbaxter at gmail.com
Mon Oct 12 09:49:12 PDT 2009

On Mon, Oct 12, 2009 at 8:24 AM, Justin Johansson
<see-body-of-message-for-name at adam.com.au> wrote:
> I'm working on a mini domain specific language (called say, MyDSL) which compiles to
> (generates) D code and am thinking that it might be nice to be able to embed MyDSL statements
> directly in a D source file in manner similar to string mixins.  It's use might look something like this:
> void foo()
> {
>    MyDSLResult res = mixin( mydsl( `some-mydsl-statement-here`);
>   now_do_something_with( res);
> }

In theory that can work, and I think there have been some proofs of
concept along those lines.
But the problem is that you have to manage to write a translator for
your DSL using only the subset of D that works at compile time.

And I believe there are still memory leaks in D's CTFE engine.  So if
CTFE expressions get too complex the compiler will slow to a crawl and
eventually crash.  Ah yes, here it is:

I don't know of any other way of implementing a DSL in D, other than
using a standard run-time parser tool, which is probably the more sane
way to go here.  Unless your DSL is really simple or you just love a


More information about the Digitalmars-d-learn mailing list