Parse failed with LANGUAGE pragma
Magicloud opened this issue · 6 comments
I have checked prompted issues, do not seem like the same issue.
I have a module using GADTs extension enabled by LANGUAGE pragma. And LambdaCase enabled by Cabal default-extensions.
{-# LANGUAGE GADTs #-}
module Test where
data R m a where
R :: MonadIO m => ReaderT Context m a -> R m a
-- other codes
Then following parsing code gave me error.
let parseMode = defaultParseMode
{ parseFilename = input
, extensions = exts -- [LambdaCase]
}
in parseModuleWithComments parseMode <$> readFile input
ParseFailed l s -> fail (s ++ ": " ++ input ++ "\n" ++ show l)
setup: GADTs language extension is not enabled. Please add {-# LANGUAGE GADTs
#-} pragma at the top of your module.: Test.hs
SrcLoc "Test.hs" 6 1
Test module works with GHC 8.6.3. haskell-src-exts is 1.20.3.
What is inside exts? There should be the Language Pragmas you use.
In your case there should be GADTs inside.
I am not sure if I understand correctly. Since the error message prompted the Language Pragma, I think the line above "module Test" should work?
exts
contains the "default-extensions" from .cabal file, which does not contain GADTs since GADTs only being used in this module.
Okay so you have to include GADTs. With extensions = exts you tell haskell-src-exts which Language Pragmas it should parse. So in your case exts should be [LambdaCase, GADTs].
I see. So if the input (module Test) is unknown when I write the parser code, I have to enable all extensions?
Yes you can enable all via
extensions = [EnableExtension x | x <- [minBound..maxBound]] if you import
Language.Haskell.Exts.Extension
OK. Thank you. Did not know Language Pragma does not work for HSE.