file-modules 0.1.2.3 → 0.1.2.4
raw patch · 2 files changed
+46/−18 lines, 2 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Development.FileModules: getImportsFromHead :: NonGreedy (ModuleHeadAndImports SrcSpanInfo) -> [String]
Files
- file-modules.cabal +10/−11
- src/Development/FileModules.hs +36/−7
file-modules.cabal view
@@ -1,5 +1,5 @@ name: file-modules-version: 0.1.2.3+version: 0.1.2.4 cabal-version: >=1.10 build-type: Simple license: MIT@@ -18,11 +18,11 @@ exposed-modules: Development.FileModules build-depends:- MissingH -any,- async -any,+ MissingH,+ async, base >=4.5 && <5,- directory -any,- filepath -any,+ directory,+ filepath, haskell-src-exts >=1.17 && <2, regex-compat >= 0.95.1, regex-pcre@@ -32,15 +32,14 @@ executable file-modules main-is: Main.hs build-depends:- MissingH -any,- async -any,- base >=4.5 && <5,+ MissingH,+ async, base >=4.5 && <5,- directory -any,- filepath -any,+ directory,+ filepath, haskell-src-exts >=1.17 && <2, regex-compat >= 0.95.1,- regex-pcre -any+ regex-pcre default-language: Haskell2010 hs-source-dirs: src ghc-options: -O2 -threaded
src/Development/FileModules.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} module Development.FileModules where @@ -7,7 +8,15 @@ import Language.Haskell.Exts (ImportDecl (..), ModuleHeadAndImports (..), ModuleName (..), NonGreedy (..),- ParseResult (..), SrcLoc (..), parse)+ ParseResult (..),+#ifdef MIN_VERSION_haskell_src_exts+# if MIN_VERSION_haskell_src_exts(1,18,0)+ SrcSpanInfo,+# endif+#else+ SrcSpanInfo,+#endif+ SrcLoc (..), parse) import System.Directory import System.FilePath import Text.Regex@@ -27,15 +36,35 @@ else return [m] return (concat modules') +#ifdef MIN_VERSION_haskell_src_exts+# if MIN_VERSION_haskell_src_exts(1,18,0)+getImportsFromHead :: NonGreedy (ModuleHeadAndImports SrcSpanInfo) -> [String]+getImportsFromHead (NonGreedy (ModuleHeadAndImports _ _ _ mimports)) =+ map (helper . importModule) mimports+ where+ helper (ModuleName _ iname) = iname+# else+{-# DEPRECATED getImportsFromHead "haskell-src-exts<1.18.0 will stoped being supported in file-modules" #-}+getImportsFromHead (NonGreedy{..}) =+ map (helper . importModule) mimports+ where+ (ModuleHeadAndImports _ _ mimports) = unNonGreedy+ helper (ModuleName iname) = iname+# endif+#else+{-# WARNING getImportsFromHead "Cabal macro to detect haskell-src-exts version not defined, assuming haskell-src-exts>1.18.0" #-}+getImportsFromHead :: NonGreedy (ModuleHeadAndImports SrcSpanInfo) -> [String]+getImportsFromHead (NonGreedy (ModuleHeadAndImports _ _ _ mimports)) =+ map (helper . importModule) mimports+ where+ helper (ModuleName _ iname) = iname+#endif+ fileModules :: FilePath -> IO [String] fileModules fname = do fcontents <- readFile fname- case parse $ sanitize fcontents of- (ParseOk NonGreedy{..}) -> do- let (ModuleHeadAndImports _ _ mimports) = unNonGreedy- forM mimports $ \imp ->- let ModuleName iname = importModule imp- in return iname+ case parse $ sanitize fcontents of+ (ParseOk rheadAndImports) -> return (getImportsFromHead rheadAndImports) (ParseFailed (SrcLoc _ line col) err) -> error $ "Failed to parse module in " ++ fname ++ ":\n" ++ " (" ++ show line ++ ":" ++ show col ++ ") " ++ err ++ "\n" ++