stylish-haskell icon indicating copy to clipboard operation
stylish-haskell copied to clipboard

Imports that are not on top of file are not parsed properly.

Open wdanilo opened this issue 10 years ago • 4 comments

Hello! There is parse error while parsing some files with imports inside of file (this is possible when using CPP extension). Example file, which is not parsed correctly can be found in Cabal install: https://github.com/haskell/cabal/blob/master/cabal-install/Distribution/Client/Win32SelfUpgrade.hs

(there are imports on lines 209 and 210)

wdanilo avatar Dec 07 '13 15:12 wdanilo

Thanks for reporting, we appreciate it! I'm keeping this issue open as a reminder for myself, but please report parsing issues directly to haskell-src-exts, the library we use for parsing Haskell.

jaspervdj avatar Dec 10 '13 09:12 jaspervdj

Thank you for the information. I've reported bug to haskell-src-exts: https://github.com/haskell-suite/haskell-src-exts/issues/68

wdanilo avatar Dec 10 '13 14:12 wdanilo

haskell-src-exts cannot parse CPP. Instead, it expects to see preprocessed Haskell source. There's the hse-cpp package which does that.

However, that wouldn't help stylish-haskell because it wants to pretty-print the code back, and that'd strip all the CPP stuff and code that wasn't included by conditional compilation.

I don't think there's much you can do about it. Consider it a limitation of haskell-src-exts & stylish-haskell, and/or the price to pay for CPP.

UnkindPartition avatar Dec 10 '13 23:12 UnkindPartition

Right, thanks for the input @feuerbach!

jaspervdj avatar Dec 11 '13 10:12 jaspervdj