extracting a single declaration using haskell-src-ext

G'day! Is there an easy way to extract a single declaration from an Haskell source file and print it with the original formatting? [I could live with pretty printing, but the default prettyPrint gives me a very strange formatting where something like: main = do putStrLn "Hello" becomes: main = do putStrLn "Hello"] The closest I've got is to parse the file with comments and then get inside Module ...decls and do printExact with an empty comment list for the decl I'm interested in. This gives me the original formatting and empty lines where comments were that I can then remove. But if there was anything already out there that just take a String for the toplevel I'm interested in and convert that only, I'd love to know. Thanks, Maurizio

This can be done with HaRe, if you use the library version rather than the
built-in refactorings. It does not support 7.8.x though, and the 7.10
support is ongoing.
Alan
On Tue, Mar 17, 2015 at 6:12 PM, Maurizio Vitale
G'day!
Is there an easy way to extract a single declaration from an Haskell source file and print it with the original formatting?
[I could live with pretty printing, but the default prettyPrint gives me a very strange formatting where something like: main = do putStrLn "Hello" becomes: main = do putStrLn "Hello"]
The closest I've got is to parse the file with comments and then get inside Module ...decls and do printExact with an empty comment list for the decl I'm interested in. This gives me the original formatting and empty lines where comments were that I can then remove.
But if there was anything already out there that just take a String for the toplevel I'm interested in and convert that only, I'd love to know.
Thanks,
Maurizio
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Hello!
I wrote some code to do this quite recently, as part of an internal
tool at FP Complete. I've copied out the relevant functions and
written an example of using it here:
https://gist.github.com/mgsloan/ac77dd33326322fc6ccd
I hope that helps!
-Michael
On Tue, Mar 17, 2015 at 9:12 AM, Maurizio Vitale
G'day!
Is there an easy way to extract a single declaration from an Haskell source file and print it with the original formatting?
[I could live with pretty printing, but the default prettyPrint gives me a very strange formatting where something like: main = do putStrLn "Hello" becomes: main = do putStrLn "Hello"]
The closest I've got is to parse the file with comments and then get inside Module ...decls and do printExact with an empty comment list for the decl I'm interested in. This gives me the original formatting and empty lines where comments were that I can then remove.
But if there was anything already out there that just take a String for the toplevel I'm interested in and convert that only, I'd love to know.
Thanks,
Maurizio
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Beautiful, thanks!
On Tue, Mar 17, 2015 at 4:02 PM, Michael Sloan
Hello!
I wrote some code to do this quite recently, as part of an internal tool at FP Complete. I've copied out the relevant functions and written an example of using it here: https://gist.github.com/mgsloan/ac77dd33326322fc6ccd
I hope that helps! -Michael
G'day!
Is there an easy way to extract a single declaration from an Haskell
file and print it with the original formatting?
[I could live with pretty printing, but the default prettyPrint gives me a very strange formatting where something like: main = do putStrLn "Hello" becomes: main = do putStrLn "Hello"]
The closest I've got is to parse the file with comments and then get inside Module ...decls and do printExact with an empty comment list for the decl I'm interested in. This gives me the original formatting and empty lines where comments were that I can then remove.
But if there was anything already out there that just take a String for
On Tue, Mar 17, 2015 at 9:12 AM, Maurizio Vitale
wrote: source the toplevel I'm interested in and convert that only, I'd love to know.
Thanks,
Maurizio
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
participants (3)
-
Alan & Kim Zimmerman
-
Maurizio Vitale
-
Michael Sloan