Nice Inline Syntax for DSLs
Knud Soerensen
4tuu4k002 at sneakemail.com
Fri Feb 16 16:38:31 PST 2007
On Fri, 16 Feb 2007 16:35:46 -0700, Russell Lewis wrote:
> Originally posted in digitalmars.d.announce. I reposted here when I
> realized my mistake.
>
> We have been talking about using string imports and code mixins and
> their applicability for domain-specific languages. But the current
> design requires either that we wrap the whole sub-language as a string,
> or we store it in another file so that we can use string imports. But
> what if we allowed there to be some simple syntax which allowed us to
> say, "Here at the top is D code; below is the DSL." How about something
> like:
>
> import my_dsl_compiler;
> mixin(MyDSLCompiler!(import_rest_of_this_file));
> FIRST_LINE_OF_MY_DSL
>
> or
>
> import my_dsl_compiler;
> int main(char[][] argv) {
> // this line resolves to a lot of variable declarations
> // and functions, including a my_dsl_main()
> mixin MyDSLCompiler!(import_rest_of_this_file));
> return my_dsl_main(argv);
> }
> FIRST_LINE_OF_MY_DSL
>
> Sort of the idea is that whenever the compiler hits a line that includes
> some special keyword (in the above example, it is
> import_rest_of_this_file), it keeps on to the end of the current
> declaration, treating it as D code. The rest is assumed to be string
> data which is imported into the D code above.
>
> Think of it like a shebang line in a script, which documents how the
> rest of the code is to be handled.
>
> Russ
Well, we already have asm as a dsl.
Why not use a similar syntax like:
dslname
{
...
}
We just need a way to tell the compiler which passer to use for dslname.
More information about the Digitalmars-d
mailing list