How to highlighting subexpressions in dumped core?

Hi, one of my plugins dumps core output to the user, and this core output contains “interesting subexpressions”. I would like to highlight them (for example, with `bold :: SDoc -> SDoc`). As far as I can see, I have these options: * I copy all, or most of PprCore, and extend ppr_expr to look for the subexpressions that I care about. Obviously not nice, because of a code copy. * I extend GHC to support that. One way would be to add a new constructor to `data Tickish id = … | Highlight` so that I can wrap the interesting subexpressions in `Tick Highlight e`. That’s a bit better, and could even be useful in GHC (e.g. a linter error could highlight the lint error location), but it’d mean waiting for new compiler versions until I can make use of that, and it is still limited to subexpressions – highlighting a binder would require yet another support. * Could we extend SDoc with an operation highlightIn :: SDoc -> SDoc -> SDoc or highlightIn :: Doc -> Doc -> Doc where `highlightIn doc1 doc2` is like doc2, but any subdocument that is “ismorphic to doc1” (for whatever that means) gets highlighted? Are there other options that I might not see right now? Cheers, Joachim -- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/

I'm not keen on adding more Tick complexity -- it's a bit out of hand already, and all transformations must "do the right thing".
AnnExpr adds an annotation at every node. You could, I guess use that to annotate -- but then you'd need a pretty printer for it so you'd end up with duplication.
Worth looking at #8809 and related tickets
S
| -----Original Message-----
| From: Glasgow-haskell-users [mailto:glasgow-haskell-users-
| bounces@haskell.org] On Behalf Of Joachim Breitner
| Sent: 06 March 2018 15:27
| To: GHC users

Hi, Am Mittwoch, den 07.03.2018, 12:14 +0000 schrieb Simon Peyton Jones via Glasgow-haskell-users:
I'm not keen on adding more Tick complexity -- it's a bit out of hand already, and all transformations must "do the right thing".
AnnExpr adds an annotation at every node. You could, I guess use that to annotate -- but then you'd need a pretty printer for it so you'd end up with duplication.
Worth looking at #8809 and related tickets
these are all for CoreExpr, right? I guess I can just copy the pretty-printer code for my maybe a bit peculiar needs, it’s not too big. (Although highlights in CoreLint output would be useful for all of use.) Thanks for your input, Joachim -- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/
participants (2)
-
Joachim Breitner
-
Simon Peyton Jones