Araq/Nimrod — pull request #1069 by flaviut (2014-04-05 17:01:28+00:00)
Title: Add renderRstToJson in docutils

Added a method to render RST ASTs into JSON for debugging.

Example output:
```{"kind":"rnInner","level":0,"sons":[{"kind":"rnInner","level":0,"sons":[{"kind":"rnLeaf","text":"Rotates","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"the","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"integer","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnInlineLiteral","level":0,"sons":[{"kind":"rnLeaf","text":"i","level":0}]},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"right","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnInlineLiteral","level":0,"sons":[{"kind":"rnLeaf","text":"distance","level":0}]},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"times","level":0},{"kind":"rnLeaf","text":".","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"This","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"is","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"an","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"unsigned","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"operation","level":0},{"kind":"rnLeaf","text":",","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"the","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"sign","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"bit","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"is","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"rotated","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"like","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"any","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"other","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"bit","level":0},{"kind":"rnLeaf","text":".","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"..","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"code","level":0},{"kind":"rnLeaf","text":"-","level":0},{"kind":"rnLeaf","text":"block","level":0},{"kind":"rnLeaf","text":"::","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"Nimrod","level":0}]},{"kind":"rnBlockQuote","level":0,"sons":[{"kind":"rnInner","level":0,"sons":[{"kind":"rnLeaf","text":"assert","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"(","level":0},{"kind":"rnLeaf","text":"0b0010","level":0},{"kind":"rnLeaf","text":"_","level":0},{"kind":"rnLeaf","text":"0000","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"rotr","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"4","level":0},{"kind":"rnLeaf","text":")","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"==","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"0b0000","level":0},{"kind":"rnLeaf","text":"_","level":0},{"kind":"rnLeaf","text":"0010","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"assert","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"(","level":0},{"kind":"rnLeaf","text":"-","level":0},{"kind":"rnLeaf","text":"0b000","level":0},{"kind":"rnLeaf","text":"_","level":0},{"kind":"rnLeaf","text":"0000i8","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"rotr","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"2","level":0},{"kind":"rnLeaf","text":")","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"==","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"0b0010","level":0},{"kind":"rnLeaf","text":"_","level":0},{"kind":"rnLeaf","text":"0000i8","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"assert","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"(","level":0},{"kind":"rnLeaf","text":"0b0000","level":0},{"kind":"rnLeaf","text":"_","level":0},{"kind":"rnLeaf","text":"0010u8","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"rotr","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"2","level":0},{"kind":"rnLeaf","text":")","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"==","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"0b1000","level":0},{"kind":"rnLeaf","text":"_","level":0},{"kind":"rnLeaf","text":"0000u8","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"assert","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"(","level":0},{"kind":"rnLeaf","text":"781652","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"rotr","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"-","level":0},{"kind":"rnLeaf","text":"2","level":0},{"kind":"rnLeaf","text":")","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"==","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"(","level":0},{"kind":"rnLeaf","text":"781652","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"rotl","level":0},{"kind":"rnLeaf","text":" ","level":0},{"kind":"rnLeaf","text":"2","level":0},{"kind":"rnLeaf","text":")","level":0}]}]}]}```

The text element is not escaped exactly as specified as the JSON specifications, so JSON parsers will not parse `\uXX` back into its character, but I don't see this as being an issue for debugging.