Open athas opened 8 years ago
No, I don't see a way to ensure that each rendered line is prefixed with a string. What do you mean by "line comment syntax?" Can you provide an example? Why can't you post-process the output to add the prefix you want?
For example, if I am prettyprinting something with a Haskell-ish syntax, and I want to print some comments using --
comment notation. I don't know how many lines the Doc
corresponding to the comment will be rendered as, and just prefixing it with --
won't work if it gets rendered as multiple lines. I could manually render the Doc
to a string of (say) 80-character lines, but then the document as a whole will probably not be wrapped properly. It's the best way to do it at the moment, but not optimal.
Look at the way the align
combinator is implemented. If you know the printing width, you can use a similar technique to wrap your comment appropriately.
Is there a way to prettyprint something such that every line (when rendered) is prefixed with some string? I looked at how indentation was handled, and it looked like it had to be done as a primitive operator. This would be very useful when prettyprinting languages with line comment syntax.