haskell / pretty

Haskell Pretty-printer library
Other
69 stars 30 forks source link

Add an annotation API #19

Closed elliottt closed 9 years ago

elliottt commented 9 years ago

Inspired by the annotated-wl-pretty library used in Idris, this change provides a new API through the Text.PrettyPrint.Annotated module hierarchy that allows the annotation of documents. This amounts to adding a new annotate function that allows arbitrary metadata to be associated with sub-documents, as well as some new rendering functions:

The current state of this change is:

david-christiansen commented 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!

dterei commented 9 years ago

Awesome! Looks really good, please address one comment and then I'm happy to merge.

elliottt commented 9 years ago

OK, I just pushed a commit that makes the TextDetails field of the NoAnnot constructor strict.