How to best implement a DSL?
rikki cattermole
rikki at cattermole.co.nz
Sat Jul 28 17:01:22 UTC 2018
On 29/07/2018 4:53 AM, Robert M. Münch wrote:
> On 2018-07-28 15:43:12 +0000, rikki cattermole said:
>
>
> * Could I somehow call an external program during compilation which
> gets the DSL block as input and returns D code?
>
>
> No. But you can pre-process.
>
>
> Yes, sure, but this complicates the build-system. I preferr to use as
> few parts as possible.
>
>
>
> * Is it possible to populate such a dictonary via CTFE?
>
>
> Sort of, it can be registered, but the actual execution of the
> registration occurs at runtime.
>
>
> Yes, no problem. How is this done?
Usually either a mixin template or a string mixin that plops a module
constructor down with it calling a register function with whatever data
you happened to compute/create using CTFE.
> But you're slightly over thinking this. Write an interpreter and a
> parser. The fact that the parser can work at CTFE is irrelevant and
> almost a footnote on the page of details ;).
>
>
> Not really if you think about deployment. I want to create a single
> executable, no external files. So I somehow have to get the scripts
> included or use the compiler as generator. The main use-case is, that I
> want to use a very declarative approach for some UI parts.
You missed my point here.
There is nothing special about parsing at CTFE, you're just restricted
as to the language features you can use (e.g. no extern's), that's it.
More information about the Digitalmars-d-learn
mailing list