Writing a (dis-)assembler for 8-bit code in D - blog posts
Petar
Petar
Tue Apr 20 14:52:08 UTC 2021
On Tuesday, 20 April 2021 at 13:38:37 UTC, Brian wrote:
> [..]
>
> Looking at the mixins page here:
> https://dlang.org/articles/mixin.html, I am already
> disappointed to learn about the monkey business it won't let me
> do :) I was really hoping to radically alter the syntax of D to
> create my own language and then implement an entirely different
> language in that (I kid, but only slightly. That's exactly what
> Arthur Whitney does in his language development: K being a good
> example of this.)
>
> ~Brian
You can almost do what you want, which may be sufficient for your
needs :P
Have a look these two projects as general examples:
* https://github.com/PhilippeSigaud/Pegged
* https://vibed.org/docs#html-templates
Basically, you can embed a DSL with arbitrary syntax and
semantics in a D program, just as long as the DSL code is
encapsulated in a string mixin. So, you can either have every D
file be just a big string mixin - `mixin(myDSL("<lots of code
here>"))` (see Pegged), or you can put the DSL code as separate
files and then string-import it at compile-time from the rest of
the D code (see vibe.d).
More information about the Digitalmars-d
mailing list