module Distribution.Package (
PackageName(..),
PackageIdentifier(..),
PackageId,
InstalledPackageId(..),
Dependency(..),
thisPackageVersion,
notThisPackageVersion,
simplifyDependency,
Package(..), packageName, packageVersion,
PackageFixedDeps(..),
) where
import Distribution.Version
( Version(..), VersionRange, anyVersion, thisVersion
, notThisVersion, simplifyVersionRange )
import Distribution.Text (Text(..))
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP ((<++))
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ((<>), (<+>), text)
import qualified Data.Char as Char ( isDigit, isAlphaNum )
import Data.List ( intersperse )
newtype PackageName = PackageName String
deriving (D:Read ::
(Int -> ReadS a)
-> ReadS [a]
-> ReadPrec a
-> ReadPrec [a]
-> T:Read aRead, D:Show ::
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow, D:Eq :: (a -> a -> Bool) -> (a -> a -> Bool) -> T:Eq aEq, D:Ord ::
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> T:Ord aOrd)
instance D:Text :: (a -> Doc) -> (forall r. ReadP r a) -> T:Text aText PackageName where
disp (PackageName n) = text :: String -> DocDisp.text n :: Stringn
parse = do
ns <- sepBy1 :: ReadP r a -> ReadP r sep -> ReadP r [a]Parse.sepBy1 component :: Parser r Char Stringcomponent (char :: Char -> ReadP r CharParse.char '-')
return :: Monad m => forall a. a -> m areturn (PackageName :: String -> PackageNamePackageName (concat :: [[a]] -> [a]concat (intersperse :: a -> [a] -> [a]intersperse "-" ns :: [String]ns)))
where
component = do
cs <- munch1 :: (Char -> Bool) -> ReadP r StringParse.munch1 isAlphaNum :: Char -> BoolChar.isAlphaNum
if all :: (a -> Bool) -> [a] -> Boolall isDigit :: Char -> BoolChar.isDigit cs :: Stringcs then pfail :: ReadP r aParse.pfail else return :: Monad m => forall a. a -> m areturn cs :: Stringcs
type PackageId = PackageIdentifier
data pkgName :: PackageNamePackageIdentifier
= PackageIdentifier {
pkgName :: PackageName,
pkgVersion :: Version
}
deriving (D:Read ::
(Int -> ReadS a)
-> ReadS [a]
-> ReadPrec a
-> ReadPrec [a]
-> T:Read aRead, D:Show ::
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow, D:Eq :: (a -> a -> Bool) -> (a -> a -> Bool) -> T:Eq aEq, D:Ord ::
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> T:Ord aOrd)
instance D:Text :: (a -> Doc) -> (forall r. ReadP r a) -> T:Text aText PackageIdentifier where
disp (PackageIdentifier n v) = case v :: Versionv of
Version [] _ -> disp :: Text a => a -> Docdisp n :: Stringn
_ -> disp :: Text a => a -> Docdisp n :: Stringn (<>) :: Doc -> Doc -> Doc<> char :: Char -> DocDisp.char '-' (<>) :: Doc -> Doc -> Doc<> disp :: Text a => a -> Docdisp v :: Versionv
parse = do
n <- parse :: Text a => forall r. ReadP r aparse
v <- (char :: Char -> ReadP r CharParse.char '-' (>>) :: Monad m => forall a b. m a -> m b -> m b>> parse :: Text a => forall r. ReadP r aparse) (<++) :: ReadP a a -> ReadP r a -> ReadP r a<++ return :: Monad m => forall a. a -> m areturn (Version :: [Int] -> [String] -> VersionVersion [] :: [a][] [] :: [a][])
return :: Monad m => forall a. a -> m areturn (PackageIdentifier :: PackageName -> Version -> PackageIdentifierPackageIdentifier n :: Stringn v :: Versionv)
newtype InstalledPackageId = InstalledPackageId String
deriving (D:Read ::
(Int -> ReadS a)
-> ReadS [a]
-> ReadPrec a
-> ReadPrec [a]
-> T:Read aRead,D:Show ::
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow,D:Eq :: (a -> a -> Bool) -> (a -> a -> Bool) -> T:Eq aEq,D:Ord ::
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> T:Ord aOrd)
instance D:Text :: (a -> Doc) -> (forall r. ReadP r a) -> T:Text aText InstalledPackageId where
disp (InstalledPackageId str) = text :: String -> Doctext str :: Stringstr
parse = InstalledPackageId :: String -> InstalledPackageIdInstalledPackageId fmap :: Functor f => forall a b. (a -> b) -> f a -> f b`fmap` munch1 :: (Char -> Bool) -> ReadP r StringParse.munch1 abi_char :: Char -> Boolabi_char
where abi_char c = isAlphaNum :: Char -> BoolChar.isAlphaNum c :: Charc (||) :: Bool -> Bool -> Bool|| c :: Charc elem :: Eq a => a -> [a] -> Bool`elem` ":-_."
data Dependency = Dependency PackageName VersionRange
deriving (D:Read ::
(Int -> ReadS a)
-> ReadS [a]
-> ReadPrec a
-> ReadPrec [a]
-> T:Read aRead, D:Show ::
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow, D:Eq :: (a -> a -> Bool) -> (a -> a -> Bool) -> T:Eq aEq)
instance D:Text :: (a -> Doc) -> (forall r. ReadP r a) -> T:Text aText Dependency where
disp (Dependency name ver) =
disp :: Text a => a -> Docdisp name :: PackageNamename (<+>) :: Doc -> Doc -> Doc<+> disp :: Text a => a -> Docdisp ver :: VersionRangever
parse = do name <- parse :: Text a => forall r. ReadP r aparse
skipSpaces :: ReadP r ()Parse.skipSpaces
ver <- parse :: Text a => forall r. ReadP r aparse (<++) :: ReadP a a -> ReadP r a -> ReadP r a<++ return :: Monad m => forall a. a -> m areturn anyVersion :: VersionRangeanyVersion
skipSpaces :: ReadP r ()Parse.skipSpaces
return :: Monad m => forall a. a -> m areturn (Dependency :: PackageName -> VersionRange -> DependencyDependency name :: PackageNamename ver :: VersionRangever)
thisPackageVersion :: PackageIdentifier -> Dependency
thisPackageVersion (PackageIdentifier n v) =
Dependency :: PackageName -> VersionRange -> DependencyDependency n :: Stringn (thisVersion :: Version -> VersionRangethisVersion v :: Versionv)
notThisPackageVersion :: PackageIdentifier -> Dependency
notThisPackageVersion (PackageIdentifier n v) =
Dependency :: PackageName -> VersionRange -> DependencyDependency n :: Stringn (notThisVersion :: Version -> VersionRangenotThisVersion v :: Versionv)
simplifyDependency :: Dependency -> Dependency
simplifyDependency (Dependency name range) =
Dependency :: PackageName -> VersionRange -> DependencyDependency name :: PackageNamename (simplifyVersionRange :: VersionRange -> VersionRangesimplifyVersionRange range :: VersionRangerange)
class Package pkg where
packageId :: pkg -> PackageIdentifier
packageName :: Package pkg => pkg -> PackageName
packageName = pkgName :: PackageIdentifier -> PackageNamepkgName (.) :: (b -> c) -> (a -> b) -> a -> c. packageId :: Package pkg => pkg -> PackageIdentifierpackageId
packageVersion :: Package pkg => pkg -> Version
packageVersion = pkgVersion :: PackageIdentifier -> VersionpkgVersion (.) :: (b -> c) -> (a -> b) -> a -> c. packageId :: Package pkg => pkg -> PackageIdentifierpackageId
instance D:Package :: (pkg -> PackageIdentifier) -> T:Package pkgPackage PackageIdentifier where
packageId = id :: a -> aid
class Package pkg => PackageFixedDeps pkg where
depends :: pkg -> [PackageIdentifier]