How do I make parseModule
parse Haskell files with language extensions?
Using parseModule
from Language.Haskell.Exts
, when I try to parse the file Core.hs
from https://github.com/xmonad/xmonad/blob/master/src/XMonad/Core.hs I get the error:
XGene-exe: fromParseResult: Parse failed at [<unknown>.hs] (248:25): Illegal data/newtype declaration
This appears to be because it is using an existential type:
data Layout a = forall l. (LayoutClass l a, Read (l a)) => Layout (l a)
yet Core.hs
has the ExistentialQuantification
language extension pragma at the top:
{-# LANGUAGE ExistentialQuantification, FlexibleInstances, GeneralizedNewtypeDeriving,
MultiParamTypeClasses, TypeSynonymInstances, DeriveDataTypeable #-}
when I try it for Layout.hs
(https://github.com/xmonad/xmonad/blob/master/src/XMonad/Core.hs) I get the error
Parse failed at [<unknown>.hs] (53:1): MultiParamTypeClasses language extension is not enabled. Please add {-# LANGUAGE MultiParamTypeClasses #-} pragma at the top of your module.
despite there pragma being there:
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, PatternGuards, TypeSynonymInstances, DeriveDataTypeable #-}
Main.hs
and Operations.hs
gives the error Malformed context: FlexibleContexts is not enabled
despite having {-# LANGUAGE MultiParamTypeClasses, FlexibleContexts #-}
Config.hs
, ManageHook.hs
and Stackset.hs
parse correctly.
xmonad builds when I do a cabal build.
Thanks to the Guidance of duplode's comment, the issue was that I was using parseModule
, instead of parseFile
.
parseFile
automatically picks up the language extensions, whereas if I wanted to parse just the source code then I would have to use parseModuleWithMode
and add the relevant extensions.
parseFile
fits my use case better.