json and ddoc

Sönke Ludwig sludwig at outerproduct.org
Wed Aug 1 08:09:32 PDT 2012


Am 01.08.2012 16:07, schrieb Adam D. Ruppe:
> I'm (finally) updating my dpldocs.info website again, and
> before I just pulled names from the generated Phobos html.
>
> This time, I want to use dmd's json output to avoid dependency
> on the specific html layout of std.ddoc.
>
>
> Anyway I hit dmd -c -X -D *.d in the phobos dir. Boom, I got
> one big .json file with all the info.
>
> But, the comments aren't parsed at all.
>
>
>
> So, my question is: do we have a ddoc parser that stands alone?
>
>
> BTW: this is the complete listing from json so far:
> http://dpldocs.info/search/awesome
>
> I'm actually impressed with the speed, considering it is re-parsing
> 3 MB of generated json per load. std.variant and std.json might not
> be speed demons, but they are plenty good enough for me.
>
> The ultimate goal here is to revitalize my D search engine and to
> make it as a nice index for all functions, with brief descriptions,
> etc., hopefully for all D libs everywhere.
>
> With the html, dealing with different people's macros to parse it
> is a pain. But with the json, dmd always does it the same way, so
> with some luck, I can just add a box "upload your project's json
> file" and allow easy instant submissions for other libs.

I have a simple DDOC parser in vibe.d (*). No guarantees that the output 
is always acting the same as DMD (e.g. there is no support for special 
sections yet), but it was good enough for me so far.

Something like this should work:

import vibe.vibe;

void main(string[] args)
{
	auto fin = openFile(args[1], FileMode.Read);
	auto ddoc = cast(string)fin.readAll();
	auto html = appender!string();
	filterDdocComment(html, ddoc);

	auto fout = openFile(args[2], FileMode.CreateTrunc);
	fout.write(formatDdocComment(html.data));
}

It doesn't really have dependencies to vibe.d so ripping it out should 
also be easy.

(*) http://vibed.org/api/vibe.textfilter.ddoc#filterDdocComment

...that module is not really documented atm


More information about the Digitalmars-d mailing list