fendor / hsimport

Extend the import list of a Haskell source file
Other
38 stars 10 forks source link

Support for literate haskell #12

Closed zugz closed 7 years ago

zugz commented 7 years ago

It would be nice if hsimport could support lhs (both with latex and with '>').

dan-t commented 7 years ago

I don't see a direct way for this, because then the parsing done by haskell-src-exts would need to support it.

The only way I see is to convert the literate haskell source into haskell source, then calling hsimport and afterwards to convert back.

zugz commented 7 years ago

I don't see a direct way for this, because then the parsing done by haskell-src-exts would need to support it.

The only way I see is to convert the literate haskell source into haskell source, then calling hsimport and afterwards to convert back.

So haskell-src-exts supports parsing literate haskell, as long as you use Language.Haskell.Exts.parseFile and the file has a '.lhs' extension. But all it does is use Language.Preprocessor.Unlit.unlit from cpphs to strip down to normal haskell, which means losing the information you'd need to reconstruct the literate source.

It looks like it wouldn't be too hard to adapt unlit to keep that information, though. I might give it a go if you don't want to - would you be likely to accept a PR if I did?

dan-t commented 7 years ago

On Wed, Feb 15, 2017 at 01:42:20PM -0800, zugz wrote:

It looks like it wouldn't be too hard to adapt unlit to keep that information, though. I might give it a go if you don't want to - would you be likely to accept a PR if I did?

If I'm understanding you correctly, then this are mostly only changes to haskell-src-exts, right?

hsimport also uses haskell-src-exts for the pretty printing of import statements. So this also has to be handled for the literate haskell case.

If you can add support without some horrible hacks and add some tests for it, I've nothing against it.

zugz commented 7 years ago

On Wed, Feb 15, 2017 at 01:42:20PM -0800, zugz wrote:

It looks like it wouldn't be too hard to adapt unlit to keep that information, though. I might give it a go if you don't want to - would you be likely to accept a PR if I did?

If I'm understanding you correctly, then this are mostly only changes to haskell-src-exts, right?

Hmm. I was thinking to have it in hsimport itself. Do you think it makes more sense to have haskell-src-exts incorporate the literate part of an .lhs into its parse?

If you can add support without some horrible hacks and add some tests for it, I've nothing against it.

Great. I'd try to keep hackery to a minimum.