Closed elliottt closed 9 years ago
For those who are curious as to how these annotations can be useful, I wrote a blog post about how we use them in Idris: http://www.davidchristiansen.dk/2014/09/06/pretty-printing-idris/
The basic idea is that the annotations track semantic information about their document, which can then be rendered differently in different contexts. In Idris, we use it to have semantic coloring at the console (for example, showing type constructors and data constructors in different colors), while richer output contexts such as the Emacs REPL or tryidris.org can make information like docstrings and type annotations for names available in tooltips. It's also possible to do things like normalizing terms that occur in error messages.
It's great to see that @elliottt has implemented this for the HughesPJ interface - hopefully we'll see better REPLs all around!
Awesome! Looks really good, please address one comment and then I'm happy to merge.
OK, I just pushed a commit that makes the TextDetails field of the NoAnnot constructor strict.
Inspired by the
annotated-wl-pretty
library used in Idris, this change provides a new API through theText.PrettyPrint.Annotated
module hierarchy that allows the annotation of documents. This amounts to adding a newannotate
function that allows arbitrary metadata to be associated with sub-documents, as well as some new rendering functions:renderSpans
Render aString
as well as a list of annotations about that string, which identify sub-strings within itrenderDecorated
Render aString
while interpreting the start and end of annotated regions as parts of that stringrenderDecoratedM
Produce a monadic action, where the start and end of annotated regions are interpreted in that contextThe current state of this change is:
Text.PrettyPrint
,Text.PrettyPrint.HughesPJ
, andText.PrettyPrint.HughesPJClass
has been preserved, and should not break existing codeText.PrettyPrint.Annotated
,Text.PrettyPrint.Annotated.HughesPJ
, andText.PrettyPrint.Annotated.HughesPJClass
modules