1

When parsing haskell source files that contain #define and #if, parseFileContentsWithMode gets confused and throws an error about the hash. I tried to include MagicHash and CPP in the extension list (extns, see below) but that didn't work. I can't really change the source files because there are a lot of them.

getModule extns filePath program = fromParseResult $ parseFileContentsWithMode mode program
                         where
                                  bangPatternsExt = map parseExtension extns
                                  mode = ParseMode filePath Haskell2010 bangPatternsExt False False 

The parser failed at:

#if __GLASGOW_HASKELL__ >= 612

instance Lift ModName where
  lift = lift . modString
2
  • 1
    If it's #define and similar that's causing you problems, you don't want MagicHash, you want CPP. Commented Jul 1, 2015 at 14:48
  • I tried only adding that also, didn't work
    – rem
    Commented Jul 1, 2015 at 14:48

1 Answer 1

5

Haskell-src-exts doesn't support CPP natively (there is no issue in the GitHub issue tracker for that, but an old one on trac at http://trac.haskell.org/haskell-src-exts/ticket/27).

You can look at solution or workarounds for haskell-src-exts parsing modules with CPP failing for workarounds (using cpphs).

There is also a package called hse-cpp (https://hackage.haskell.org/package/hse-cpp) that looks like it can run cpphs for you, but I haven't used it, and it doesn't seem to get updated a lot.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.