Nice Inline Syntax for DSLs
Tyler Knott
tywebmail at mailcity.com
Fri Feb 16 17:08:47 PST 2007
Knud Soerensen wrote:
> On Fri, 16 Feb 2007 16:35:46 -0700, Russell Lewis wrote:
>
> 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.
I was thinking of a similar syntax as well, except it would look like this:
# dsl(compilerFunc[, ...])
# {
# DSL GOES HERE
# }
With three restrictions:
1. All curly braces within the DSL must be balanced.
2. compilerFunc must be evaluable at compile time.
3. compilerFunc must use the signature char[] function(char[][, ...]).
The code between the braces would be passed in to compilerFunc as the
first argument, any arguments to the DSL statement after the complier
function would be passed as the remaining arguments to the compiler
function (like how opApply overloading works), and the return value of
the function would be implicitly mixed in where the dsl declaration
occurs. (This of course depends on Walter fixing compile-time
evaluation of functions for const initialization, which should be done
in the next release of DMD.)
More information about the Digitalmars-d
mailing list