Why is D unpopular?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Sun May 15 13:41:31 UTC 2022
On Sunday, 15 May 2022 at 13:12:29 UTC, zjh wrote:
> `Macros` match can be done just with `mixin`.
Not really, because they contain fragments of C-code. So if you
inject them straight into D-code it may look like gibberish to
the D compiler. You also cannot parse a C fragment without
knowing the context.
So what you need to do is to use a parser that allows mixing D
and C code under the assumption that the C-tokens are tagged as C
and the D-tokens are tagged as D.
This is probably possible (maybe requires some adjustments) since
D already is very close to C in its structure.
E.g. assume a C-macro called FUNCTION:
```$FUNCTION(void,functionname){…}```
After lexing the lexer annotate the tokens in the expanded
FUNCTION macro as coming from a C-macro, and it will try at
different branch in the parser that is oriented towards C and not
D. From this it will build a D-compatible function signature
before adding the body of the function (which is regular D code).
More information about the Digitalmars-d
mailing list