Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-mode pretty-printer #13

Open
achudnov opened this issue Aug 23, 2013 · 2 comments
Open

Multi-mode pretty-printer #13

achudnov opened this issue Aug 23, 2013 · 2 comments

Comments

@achudnov
Copy link
Member

Wouldn't it be nice if we could use the same pretty-printer to generate well-formatted, "pretty" source representation -- as well as the minified source representation (for use in minifiers, compilers back-ends etc)?
Another use case is pretty-printing annotation fields as comments (useful in debugging, generating type annotations etc.). I'm using a private fork where the pretty-printer does that. I'd like the functionality to be available to everyone, but I want the possibility to disable it.
Yet another use-case is generating source-maps which would also require a modified pretty-printer. I'm not sure of the scope of the modifications, but I'm certain it's not limited to merely omitting certain characters depending on flags (which seems the case for the previous two use-cases).

Anyway, I've been tinkering with a multi-mode pretty-printing library that would, hopefully, help in writing a multi-mode printer for language-ecmascript. But I'd like feedback on the idea as a whole and any additional use-cases you can think of.

@achudnov
Copy link
Member Author

achudnov commented Sep 6, 2013

It is my understanding that BlazeBuilder (as well as Data.Text.Builder and Data.ByteString.Builder) is the king when it comes to performance and memory usage in generating text programmatically, so, perhaps, we could consider switching to it as a part of the effort to update the pretty-printer for ECMAScript5.

@achudnov
Copy link
Member Author

achudnov commented Jan 2, 2016

https://hackage.haskell.org/package/annotated-wl-pprint seems helpful for pretty-printing comments and, potentially, generating source maps. See https://hackage.haskell.org/package/annotated-wl-pprint-0.7.0/docs/Text-PrettyPrint-Annotated-Leijen.html#v:displayDecorated and https://hackage.haskell.org/package/annotated-wl-pprint-0.7.0/docs/Text-PrettyPrint-Annotated-Leijen.html#v:displaySpans.

Note, that pretty implements the same functionality, but in a cleaner way (less code repetition): https://github.com/haskell/pretty/blob/master/src/Text/PrettyPrint/Annotated/HughesPJ.hs#L950 Still, WadlerLeijen tends to produce prettier output, so it might be a good idea to backport the implementation in pretty to annotated-wl-pprint. Another potential improvement would be to parametrize rendering with any instance of Monoid and IsString so we could plug-in Text.Builder and Data.ByteString.Builder with no effort. All in all, these improvements would bring an interface that is generic enough to meet all of our use cases: (1) pretty output with (2) optional annotation printing, (3) SourceMap generation and (4) minified output. Which obviates my old and semi-coherent dreams in achudnov/printers@25b7e08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant