json generation from ddoc: painfully close

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 8 00:32:10 PST 2015


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


More information about the Digitalmars-d mailing list