Ddoc macro syntax
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Thu Sep 15 16:53:10 PDT 2016
On 9/15/2016 4:06 AM, Andrei Alexandrescu wrote:
> I was thinking more about it and figured we could introduce a special macro at
> the very beginning of a .ddoc file or "Macros:" section called
> DDOC_MACRO_CALL_SYNTAX. It may be defined one of the following:
>
> DDOC_MACRO_CALL_SYNTAX = DDOC
>
> That's today's syntax.
>
> DDOC_MACRO_CALL_SYNTAX = CPP
>
> A macro will be invoked as MACRO(a1, a2).
That will break every usage of function calling examples. (It works in CPP
because if MACRO is not a macro, the text is left unchanged. In Ddoc, a
non-existent macro is replaced by the empty string.)
> DDOC_MACRO_CALL_SYNTAX = $CPP
>
> A macro will be invoked as $MACRO(a1, a2)
>
> DDOC_MACRO_CALL_SYNTAX = LaTeX
>
> Macro invocation is \MACRO{a1}{a2}.
>
> This definition is modular, i.e. it doesn't carry beyond the current document
> (otherwise the semantics of a .dd file depends on the .ddoc file(s) it's used
> with).
>
> Macro definitions stay the same using $1, $2 etc. but macros invoked by them
> would need to obey the DDOC_MACRO_CALL_SYNTAX defined at the top.
Alternatives:
1. accept more than one syntax
2. have the first encountered usage set the mode
More information about the Digitalmars-d
mailing list