Skip to content

Commit ed7e830

Browse files
authored
Merge pull request #3365 from ntrel/ddoc-expansion
[spec/ddoc] Improve macro expansion section
2 parents d2fc299 + 1a79212 commit ed7e830

File tree

1 file changed

+58
-24
lines changed

1 file changed

+58
-24
lines changed

spec/ddoc.dd

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ $(P
495495
$(H3 $(LNAME2 inline_code, Inline Code))
496496

497497
$(P
498-
Inline code can be written between backtick characters ($(BACKTICK)), similarly
498+
Inline code can be written between backtick characters (`$(BACKTICK)`), similarly
499499
to the syntax used on GitHub, Reddit, Stack Overflow, and other websites. Both
500-
the opening and closing $(BACKTICK) character must appear on the same line to trigger this
500+
the opening and closing `$(BACKTICK)` character must appear on the same line to trigger this
501501
behavior.
502502
)
503503

@@ -508,7 +508,7 @@ $(P
508508
)
509509

510510
$(P
511-
A literal backtick character can be output either as a non-paired $(BACKTICK) on a single
511+
A literal backtick character can be output either as a non-paired `$(BACKTICK)` on a single
512512
line or by using the `$(DOLLAR)(BACKTICK)` macro.
513513
)
514514

@@ -913,9 +913,11 @@ $(H2 $(LNAME2 macros, Macros))
913913
$(P
914914
The documentation comment processor includes a simple macro
915915
text preprocessor.
916-
When a $(DOLLAR)($(I NAME)) appears
917-
in section text it is replaced with $(I NAME)s corresponding
918-
replacement text.)
916+
When $(D $)`(NAME)` appears
917+
in section text it is replaced with the corresponding `NAME` macro's
918+
replacement text.
919+
Macros can take arguments: $(D $)`(NAME argument)`.
920+
)
919921

920922
For example:
921923
---------
@@ -934,10 +936,10 @@ $(P
934936
---------
935937

936938
$(P
937-
The above would generate the following output:)
939+
The above would generate output such as:)
938940

939941
------------------------------------
940-
<h1>test</h1>
942+
<h1>math</h1>
941943
<dl><dt><big><a name="sum"></a>int <u>sum</u>(int <i>a</i>, int <i>b</i>);
942944
</big></dt>
943945
<dd>This function returns the <u>sum</u> of <u><i>a</i></u> and <u><i>b</i></u>.
@@ -948,33 +950,65 @@ $(P
948950

949951
$(P
950952
The replacement text is recursively scanned for more macros.
951-
If a macro is recursively encountered, with no argument or with
953+
If found, they are expanded in turn.
954+
If a macro already expanded is recursively encountered, with no argument or with
952955
the same argument text as the enclosing macro, it is replaced
953956
with no text.
957+
)
958+
$(UL
959+
$(LI
954960
Macro invocations that cut across replacement text boundaries are
955961
not expanded.
956-
If the macro name is undefined, the replacement text has no characters
957-
in it.
958-
If a $(DOLLAR)(NAME) is desired to exist in the output without being
959-
macro expanded, the $(DOLLAR) should be $(LINK2 #punctuation_escapes,
962+
)
963+
$(LI
964+
If the macro name is undefined, the replacement text will
965+
be $(D $)`(DDOC_UNDEFINED_MACRO(NAME))`. This defaults to empty.
966+
)
967+
$(LI
968+
If $(D $)`(NAME)` is required to exist in the output without being
969+
macro expanded, the `$` can be $(RELATIVE_LINK2 punctuation_escapes,
960970
backslash-escaped): `\$`.
971+
)
961972
)
962973

974+
$(H3 $(LNAME2 macro_arguments, Macro Arguments))
975+
963976
$(P
964-
Macros can have arguments. Any text from the end of the identifier
965-
to the closing $(SINGLEQUOTE $(RPAREN)) is the $(DOLLAR)0 argument.
966-
A $(DOLLAR)0 in the replacement text is
967-
replaced with the argument text.
968-
If there are commas in the argument text, $(DOLLAR)1 will represent the
969-
argument text up to the first comma, $(DOLLAR)2 from the first comma to
970-
the second comma, etc., up to $(DOLLAR)9.
971-
$(DOLLAR)+ represents the text from the first comma to the closing $(SINGLEQUOTE $(RPAREN)).
972-
The argument text can contain nested parentheses, "" or '' strings,
977+
When invoking a macro, any text from the end of the identifier
978+
to the closing $(SINGLEQUOTE $(RPAREN)) is passed as arguments to
979+
the macro, and can be referred to using the
980+
$(D $)`0` parameter inside the macro definition.
981+
A $(D $)`0` in the replacement text is
982+
replaced with the text of each argument, separated by commas.
983+
)
984+
$(P
985+
If there are commas in the argument text, this denotes multiple arguments.
986+
Inside a macro definition, $(D $)`1` will represent the
987+
argument text up to the first comma, $(D $)`2` from the first comma to
988+
the second comma, etc., up to $(D $)`9`.
989+
$(D $)`+` represents the text from the first comma to the closing $(SINGLEQUOTE $(RPAREN)).
990+
)
991+
$(UL
992+
$(LI
993+
The argument text can contain nested parentheses, `""` or `''` strings,
973994
$(D <)$(D !--) $(D ...) $(D --)$(D >) comments, or tags.
995+
)
996+
$(LI
974997
If stray, unnested parentheses are used, they can be
975-
$(LINK2 #punctuation_escapes, backslash-escaped): `\(` or `\)`.
998+
$(RELATIVE_LINK2 punctuation_escapes, backslash-escaped): `\(` or `\)`.
999+
)
1000+
$(LI
1001+
Any literal commas not intended as an argument separator can be
1002+
escaped when invoking a macro expecting separate arguments.
1003+
Defining an `ARGS=`$(D $)`0` macro can be useful to handle commas -
1004+
these are equivalent:
1005+
* $(D $)`(FOO one, `$(D $)`(ARGS two, dwa, dos), three)`
1006+
* $(D $)`(FOO one, two\, dwa\, dos, three)`.
1007+
)
9761008
)
9771009

1010+
$(H3 $(LNAME2 macro_definitions, Macro Definitions))
1011+
9781012
$(P
9791013
Macro definitions come from the following sources,
9801014
in the specified order:
@@ -987,7 +1021,7 @@ $(P
9871021
or $(DDSUBLINK dmd-linux, dmd_conf, dmd.conf) DDOCFILE setting.)
9881022
$(LI Definitions from *.ddoc files specified on the command line.)
9891023
$(LI Runtime definitions generated by Ddoc.)
990-
$(LI Definitions from any Macros: sections.)
1024+
$(LI Definitions from any `Macros:` sections.)
9911025
)
9921026

9931027
$(P

0 commit comments

Comments
 (0)