www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - A nice inline syntax for DSLs

reply Russell Lewis <webmaster villagersonline.com> writes:
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
Feb 16 2007
parent Russell Lewis <webmaster villagersonline.com> writes:
sorry for the bother.
Feb 16 2007