Special Code String for mixins
Robert M. Münch
robert.muench at saphirion.com
Wed Mar 14 07:58:56 UTC 2018
On 2017-03-15 13:50:28 +0000, Inquie said:
> I hate building code strings for string mixins as it's very ugly and
> seems like a complete hack.
> ...
Even a bit old, I would like to pick-up this topic, as I totally agree
with the statement.
Thinking this a bit further, it would be very nice to have a way to
specify DSL inside D code, without having to fallback to strings.
Some (not fully thought through) ideas:
1. Why not use something like: mixin {...} and have normal D code
between the braces? This D code is implicitly converted to a string and
used accordingly. Variables etc. can all be used and have scope rules
like D with the mixing {...} scope being the top-level scope for this
code-block. Inside the mixin scope an AST could be build, which is than
used as return value.
2. For a DSL two things are necessary: A parser for the DSL and an
interface to access D identifiers. Something like: dsl (myparser,
d_id1, d_id2, ..., d_idN) {... my-dsl-code ...} Inside the DSL parser I
get access to the listed D identifiers while I'm mostly free to design
the syntax of my DSL code as I like.
Being able to switch to a fitting syntax for things like database
access, declarative GUIs etc. can make the codebase so much more
maintainable than having to stick to the main language syntax.
There are very few languages that care about proper and simple DSL
handling, IMO a much underestimated design principle.
--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
More information about the Digitalmars-d
mailing list