Commit 1517ab38 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Split ParseUtils module out of Utils module

parent ba260af9
......@@ -44,7 +44,8 @@ import qualified Distribution.Simple.Setup as Cabal
import Distribution.Verbosity (Verbosity, normal)
import Hackage.Types (RemoteRepo(..), Repo(..), Username, Password)
import Hackage.Utils
import Hackage.ParseUtils
import Hackage.Utils (readFileIfExists)
import Distribution.Simple.Utils (notice, warn)
......
......@@ -31,7 +31,7 @@ import System.Directory (doesFileExist, createDirectoryIfMissing)
import Hackage.Types (UnresolvedDependency (..), Repo(..), repoURL,
PkgInfo, packageURL, pkgInfoId, packageFile, packageDir)
import Hackage.Dependency (resolveDependencies, packagesToInstall)
import Hackage.Utils
import Hackage.Utils (showDependencies)
import Hackage.HttpUtils (getHTTP)
import Distribution.Package (showPackageId)
......
......@@ -15,7 +15,7 @@ module Hackage.Info where
import Hackage.Dependency
import Hackage.Fetch
import Hackage.Types
import Hackage.Utils
import Hackage.Utils (showDependencies)
import Distribution.Package (showPackageId)
import Distribution.ParseUtils (showDependency)
......
......@@ -25,7 +25,7 @@ import Hackage.Fetch (fetchPackage)
import Hackage.Tar (extractTarGzFile)
import Hackage.Types (UnresolvedDependency(..), PkgInfo(..), FlagAssignment,
Repo)
import Hackage.Utils
import Hackage.Utils (showDependencies)
import Distribution.Simple.Compiler (Compiler, PackageDB(..))
import Distribution.Simple.Program (ProgramConfiguration, defaultProgramConfiguration)
......
module Hackage.Utils where
module Hackage.ParseUtils where
import Distribution.Compat.ReadP (ReadP, readP_to_S, pfail, get, look, choice, (+++))
import Distribution.Package (PackageIdentifier(..), parsePackageId)
......@@ -18,17 +18,6 @@ import System.IO.Error (isDoesNotExistError)
import Text.PrettyPrint.HughesPJ (Doc, render, vcat, text, (<>), (<+>))
readFileIfExists :: FilePath -> IO (Maybe String)
readFileIfExists path =
catchJust fileNotFoundExceptions
(fmap Just (readFile path))
(\_ -> return Nothing)
fileNotFoundExceptions :: Exception -> Maybe IOError
fileNotFoundExceptions e =
ioErrors e >>= \ioe -> guard (isDoesNotExistError ioe) >> return ioe
showPError :: PError -> String
showPError err = let (ml,msg) = locatedErrorMsg err
in maybe "" (\l -> "On line " ++ show l ++ ": ") ml ++ msg
......@@ -87,10 +76,6 @@ stringNoCase this = look >>= scan this
scan (x:xs) (y:ys) | toLower x == toLower y = get >> scan xs ys
scan _ _ = pfail
showDependencies :: [Dependency] -> String
showDependencies = concat . intersperse ", " . map (show . showDependency)
parseDependencyOrPackageId :: ReadP r Dependency
parseDependencyOrPackageId = parseDependency +++ liftM pkgToDep parsePackageId
where pkgToDep p = case pkgVersion p of
......
......@@ -44,7 +44,7 @@ import Distribution.Simple.Setup (Flag, toFlag, fromFlagOrDefault, flagToList)
import Distribution.Verbosity (Verbosity, normal, flagToVerbosity, showForCabal)
import Hackage.Types (UnresolvedDependency(..), Username, Password)
import Hackage.Utils (readPToMaybe, parseDependencyOrPackageId)
import Hackage.ParseUtils (readPToMaybe, parseDependencyOrPackageId)
import Data.Monoid (Monoid(..))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment