Nice Inline Syntax for DSLs

Tyler Knott tywebmail at mailcity.com
Tue Feb 20 14:00:28 PST 2007


Knud Soerensen wrote:
> On Fri, 16 Feb 2007 19:08:47 -0600, Tyler Knott wrote:
> 
> No, I meant something like.
> 
> compilerFunc draw[, ...] 
> { 
> ...   // parser code for the draw dsl.   
> };
> 
> and then it is used like
> 
> draw
> {
> moveto x,y;
> circle(2.0);
> ...
> }
> 
> the should be no need to repeat "compilerFunc[, ...]"
> every time the dsl is needed.

I don't think you're quite understanding what I meant.  For your draw 
example, it'd look like this

char[] draw(char[] rawcode)
{
	//process rawcode and return D code
}

dsl(draw)
{
	move x,y;
	circle(2.0);
	...
}

which translates to:

mixin(draw(`
	move x,y;
	circle(2.0);
	...
`));

The only real differences between our syntaxes is that I require the 
"dsl" keyword every time this syntax is used, and the compiler functions 
are just standard functions (with the two restrictions mentioned in my 
post).



More information about the Digitalmars-d mailing list