json generation from ddoc: painfully close

Rikki Cattermole via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 8 01:14:25 PST 2015


On 8/01/2015 9:32 p.m., Andrei Alexandrescu wrote:
> I just experimented with a battery of macros (json.ddoc) for generating
> json via ddoc. Results for std.algorithm are in
> http://paste.ofcode.org/DFnxChvmRGJiXYpYYk2XWr.
>
> There are a couple of things that make the generated json invalid:
>
> 1. I couldn't get escaping to work. My ESCAPES is:
>
> ESCAPES=/\/\\/ /"/\"/ /&/&/ /</</ />/>/
>
> So single backslashes will be doubled and quotes will be backslashed.
> Nice. The trouble is, escaping only does its job sometimes but not
> always. I haven't yet figured the circumstances.
>
> 2. This was mentioned before - paragraph, whitespace and especially
> newline handling are handled rather poorly in ddoc. The generated json
> is full of newlines in the middle of strings, which are invalid in json
> (\n must be used). I think every paragraph should be enclosed in a
> $(DDOC_PARAGRAPH) macros that has single newlines replaced with spaces.
> Alternatively, a built-in macro could escape strings appropriately.
>
> 3. Some descriptions feature multiple examples, leading to duplicate
> "DDOC_EXAMPLES" keys. Json strongly discourages (at least) duplicate
> keys in objects. There is no way to have some autoincrement thing that
> generates "DDOC_EXAMPLES_1", "DDOC_EXAMPLES_2" etc. It could be argued
> that that's an issue with the source, not the generator.
>
> That said, this is pretty much it. No other major impediments seem to
> stop the show. Thoughts and ideas on how to get this to work?
>
>
> Andrei

Well we could do the evil method of enabling calling of code from a 
macro. There should be enough information to do that?
We have CTFE, might as well use it.


More information about the Digitalmars-d mailing list