is there a way to alter every line of an SDoc?

Norman Ramsey nr at cs.tufts.edu
Mon Dec 6 21:24:46 UTC 2021


 > > I'm emitting code in which I want to prettyprint the contents
 > > of a Cmm Block as a comment, by which I mean putting `--` to the left
 > > of *each* line of the rendered Cmm Block.  Using GHC.Utils.Outputable,
 > > is this even possible?  How would I tackle it?  (The Haddock page
 > > does not suggest any obvious combinators.)
 > >
 > It's not easy. One (rather horrible) approach would be to render the
 > document to a string, split the output into lines and add the comment
 > symbols, and then splice the result into another document.

I'd be willing to go there, except I don't know how I would guess the
width of the string I'm hoping to render to.  Maybe it wouldn't matter.

 > Perhaps you could rather use block comment syntax? This would be
 > much easier.

Alas, one goal is to make the comment very obvious to the human
reader.

Some prettyprinters can be jiggered to insert a specified string at
every line break.  But I gather SDoc is not one of those.  *Sadness*


N



More information about the ghc-devs mailing list