parseModule 无法将某些语言扩展识别为已启用

parseModule does not recognize some language extensions as enabled

如何让 parseModule 解析带有语言扩展名的 Haskell 文件?

使用 Language.Haskell.Exts 中的 parseModule,当我尝试从 https://github.com/xmonad/xmonad/blob/master/src/XMonad/Core.hs 中解析文件 Core.hs 时,出现错误:

XGene-exe: fromParseResult: Parse failed at [<unknown>.hs] (248:25): Illegal data/newtype declaration

这似乎是因为它使用了存在类型:

data Layout a = forall l. (LayoutClass l a, Read (l a)) => Layout (l a)

然而 Core.hs 在顶部有 ExistentialQuantification 语言扩展编译指示:

{-# LANGUAGE ExistentialQuantification, FlexibleInstances, GeneralizedNewtypeDeriving,
             MultiParamTypeClasses, TypeSynonymInstances, DeriveDataTypeable #-}

当我尝试 Layout.hs (https://github.com/xmonad/xmonad/blob/master/src/XMonad/Core.hs) 时,我得到了错误 Parse failed at [<unknown>.hs] (53:1): MultiParamTypeClasses language extension is not enabled. Please add {-# LANGUAGE MultiParamTypeClasses #-} pragma at the top of your module. 尽管那里有 pragma:

{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, PatternGuards, TypeSynonymInstances, DeriveDataTypeable #-}

Main.hsOperations.hs 给出错误 Malformed context: FlexibleContexts is not enabled 尽管有 {-# LANGUAGE MultiParamTypeClasses, FlexibleContexts #-}

Config.hsManageHook.hsStackset.hs 正确解析。

xmonad 在我进行 cabal 构建时构建。

感谢 duplode 的评论指导,问题是我使用的是 parseModule,而不是 parseFile

parseFile 自动选择语言扩展,而如果我只想解析源代码,那么我将不得不使用 parseModuleWithMode 并添加相关的扩展。

parseFile 更适合我的用例。