dlang / ddox

Advanced D documentation engine
MIT License
63 stars 21 forks source link

std.exception.assumeUnique ddox has weird example errors #204

Open schveiguy opened 6 years ago

schveiguy commented 6 years ago

Hard to explain, I'm not sure what's happening, but the examples seem to be incorrectly parsed:

https://dlang.org/library/std/exception/assume_unique.html

Biotronic commented 6 years ago

My first though was the RUNNABLE_EXAMPLE macro was incorrectly expanded - it invokes DIVC, which invokes TC. In the end, the </div> part is escaped before it's included in the page, and the raw example code is dumped verbatim into the generated HTML. The fact the last two examples are not mutilated in this way (they are not using the RUNNABLE_EXAMPLE macro) further indicates this might be the reason.

There seems to be more to it though - ifThrown also uses the RUNNABLE_EXAMPLE macro, and does not exhibit the same issue. Looking at the examples, those which fail contain a function right inside the ---- blocks, and each line starts with an asterisk, while those who work, exhibit neither of those features. Example failing:

 * $(RUNNABLE_EXAMPLE
 * ----
 * string letters() pure
 * {
 *   char[] result = new char['z' - 'a' + 1];
 *   foreach (i, ref e; result)
 *   {
 *     e = cast(char)('a' + i);
 *   }
 *   return result;
 * }
 * ----
 * )

Example working:

$(RUNNABLE_EXAMPLE
--------------------
//Revert to a default value upon an error:
assert("x".to!int().ifThrown(0) == 0);
--------------------
)

I can't get ddox to compile (running into https://issues.dlang.org/show_bug.cgi?id=17508), so figuring out the root cause is kinda hard. Hope this will be helpful to someone.

schveiguy commented 6 years ago

Hm... it's possible to use the d auto tester to check some theories. We can create a PR that adds * to the example that works, and check the result from the tester.

wilzbach commented 6 years ago

I can't get ddox to compile (running into https://issues.dlang.org/show_bug.cgi?id=17508)

Did you try to build it with mscoff?

wilzbach commented 6 years ago

The problem is that DDox throws away newline when processing macros. We can workaround this directly at dlang.org: https://github.com/dlang/dlang.org/pull/2364