{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.PackageId
( PackageIdentifier(..)
, PackageId
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Version
( Version, nullVersion )
import qualified Distribution.Compat.ReadP as Parse
import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint as Disp
import Distribution.Compat.ReadP
import Distribution.Text
import Distribution.Parsec.Class
( Parsec(..) )
import Distribution.Pretty
import Distribution.Types.PackageName
type PackageId = PackageIdentifier
data PackageIdentifier
= PackageIdentifier {
pkgName :: PackageName,
pkgVersion :: Version
}
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
instance Binary PackageIdentifier
instance Pretty PackageIdentifier where
pretty (PackageIdentifier n v)
| v == nullVersion = pretty n
| otherwise = pretty n <<>> Disp.char '-' <<>> pretty v
instance Text PackageIdentifier where
parse = do
n <- parse
v <- (Parse.char '-' >> parse) <++ return nullVersion
return (PackageIdentifier n v)
instance Parsec PackageIdentifier where
parsec = PackageIdentifier <$>
parsec <*> (P.char '-' *> parsec <|> pure nullVersion)
instance NFData PackageIdentifier where
rnf (PackageIdentifier name version) = rnf name `seq` rnf version