@@ -38,7 +38,6 @@ import qualified HeaderInfo as Hdr
38import MkIface
38import MkIface
39import StringBuffer as SB
39import StringBuffer as SB
40import TidyPgm
40import TidyPgm
41−import qualified GHC.LanguageExtensions as LangExt
43import Control.Monad.Extra
42import Control.Monad.Extra
44import Control.Monad.Except
43import Control.Monad.Except
@@ -264,6 +263,7 @@ getModSummaryFromBuffer fp contents dflags parsed = do
264 then (HsBootFile, \newExt -> stem <.> newExt ++ "-boot")
263 then (HsBootFile, \newExt -> stem <.> newExt ++ "-boot")
265 else (HsSrcFile , \newExt -> stem <.> newExt)
264 else (HsSrcFile , \newExt -> stem <.> newExt)
267-- | Given a buffer, flags, file path and module summary, produce a
267-- | Given a buffer, flags, file path and module summary, produce a
268-- parsed module (or errors) and any parse warnings.
268-- parsed module (or errors) and any parse warnings.
269parseFileContents
269parseFileContents
@@ -273,27 +273,8 @@ parseFileContents
273 -> Maybe SB.StringBuffer -- ^ Haskell module source text (full Unicode is supported)
273 -> Maybe SB.StringBuffer -- ^ Haskell module source text (full Unicode is supported)
274 -> ExceptT [FileDiagnostic] m ([FileDiagnostic], ParsedModule)
274 -> ExceptT [FileDiagnostic] m ([FileDiagnostic], ParsedModule)
275parseFileContents sourcePlugin filename mbContents = do
275parseFileContents sourcePlugin filename mbContents = do
276+ (contents, dflags) <- preprocessor filename mbContents
276 let loc = mkRealSrcLoc (mkFastString filename) 1 1
277 let loc = mkRealSrcLoc (mkFastString filename) 1 1
277− contents <- liftIO $ maybe (hGetStringBuffer filename) return mbContents
278− let isOnDisk = isNothing mbContents
280− -- unlit content if literate Haskell ending
281− (isOnDisk, contents) <- if ".lhs" `isSuffixOf` filename
283− dflags <- getDynFlags
284− newcontent <- liftIO $ runLhs dflags filename mbContents
285− return (False, newcontent)
286− else return (isOnDisk, contents)
288− dflags <- ExceptT $ parsePragmasIntoDynFlags filename contents
289− (contents, dflags) <-
290− if not $ xopt LangExt.Cpp dflags then
291− return (contents, dflags)
293− contents <- liftIO $ runCpp dflags filename $ if isOnDisk then Nothing else Just contents
294− dflags <- ExceptT $ parsePragmasIntoDynFlags filename contents
295− return (contents, dflags)
297 case unP Parser.parseModule (mkPState dflags contents loc) of
278 case unP Parser.parseModule (mkPState dflags contents loc) of
298 PFailed _ locErr msgErr ->
279 PFailed _ locErr msgErr ->
299 throwE $ diagFromErrMsg "parser" dflags $ mkPlainErrMsg dflags locErr msgErr
280 throwE $ diagFromErrMsg "parser" dflags $ mkPlainErrMsg dflags locErr msgErr
@@ -330,16 +311,3 @@ parseFileContents sourcePlugin filename mbContents = do
331 warnings = diagFromErrMsgs "parser" dflags warns
312 warnings = diagFromErrMsgs "parser" dflags warns
332 pure (warnings, pm)
313 pure (warnings, pm)
335−-- | This reads the pragma information directly from the provided buffer.
336−parsePragmasIntoDynFlags
340− -> m (Either [FileDiagnostic] DynFlags)
341−parsePragmasIntoDynFlags fp contents = catchSrcErrors "pragmas" $ do
342− dflags0 <- getSessionDynFlags
343− let opts = Hdr.getOptions dflags0 contents fp
344− (dflags, _, _) <- parseDynamicFilePragma dflags0 opts