Skip to content

Commit

Permalink
Merge pull request #565 from AndrejMitrovic/Fix1574
Browse files Browse the repository at this point in the history
Issue 1574 - Add a simple example of macro substitution.
  • Loading branch information
MartinNowak committed May 5, 2014
2 parents bc07b66 + 810afe5 commit b558bb2
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions ddoc.dd
Expand Up @@ -559,8 +559,40 @@ $(P
text preprocessor.
When a $(DOLLAR)($(I NAME)) appears
in section text it is replaced with $(I NAME)'s corresponding
replacement text.
The replacement text is then recursively scanned for more macros.
replacement text.)

For example:
---------
/**
Macros:
PARAM = <u>$1</u>
MATH_DOCS = <a href="http://dlang.org/phobos/std_math.html">Math Docs</a>
*/
module math;

/**
* This function returns the sum of $(PARAM a) and $(PARAM b).
* See also the $(MATH_DOCS).
*/
int sum(int a, int b) { return a + b; }
---------

$(P
The above would generate the following output:

------------------------------------
<h1>test</h1>
<dl><dt><big><a name="sum"></a>int <u>sum</u>(int <i>a</i>, int <i>b</i>);
</big></dt>
<dd>This function returns the <u>sum</u> of <u><i>a</i></u> and <u><i>b</i></u>.
See also the <a href="http://dlang.org/phobos/std_math.html">Math Docs</a>.
</dd>
</dl>
------------------------------------
)

$(P
The replacement text is recursively scanned for more macros.
If a macro is recursively encountered, with no argument or with
the same argument text as the enclosing macro, it is replaced
with no text.
Expand Down

0 comments on commit b558bb2

Please sign in to comment.