Pretty Printing with position logging

Hi

I have added a feature to the Pretty library and I think others could need this as well. That's why I want to show it to you and I am eager to here what you think about it. It's about collecting a log of which Docs ended up where in the output string.

Motivation: The Ocram compiler [1] is a source to source compiler that amongst other things needs to keep track of the mapping of input rows and columns to output rows and columns. It uses the Language.C library which in turn uses the Pretty library for printing.

To perform its task the Ocram compiler needs to know which parts of the AST have been rendered where in the output document. To this end I have patched the Pretty library to support augmenting Doc objects with callbacks. When such a Doc is rendered the callback is called with the current row and column of the output document. Now I can change the Pretty instances to augment the Docs of the AST objects in question and I get a nice, accurate log of which part of the output AST ended where.

The current status of the patch is complete, as I am already using it for Ocram. But it lacks more test cases and anything else you would premise in order to accept the patches for upstream. I am willing to perform the additional work, as I would like to avoid inofficial dependencies for my project.

What do you think?

Greetings

Alex

[1] http://github.com/copton/ocram