module Distribution.Types.PackageVersionConstraint (
PackageVersionConstraint(..),
thisPackageVersionConstraint,
simplifyPackageVersionConstraint,
) where
import Distribution.Compat.Prelude
import Prelude ()
import Distribution.Parsec
import Distribution.Pretty
import Distribution.Types.PackageId
import Distribution.Types.PackageName
import Distribution.Types.Version
import Distribution.Types.VersionRange.Internal
import Distribution.Version (simplifyVersionRange)
import qualified Distribution.Compat.CharParsing as P
data PackageVersionConstraint = PackageVersionConstraint PackageName VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
instance Binary PackageVersionConstraint
instance Structured PackageVersionConstraint
instance NFData PackageVersionConstraint where rnf = genericRnf
instance Pretty PackageVersionConstraint where
pretty (PackageVersionConstraint name ver) =
pretty name <+> pretty ver
instance Parsec PackageVersionConstraint where
parsec = do
PackageIdentifier name ver <- parsec
if ver == nullVersion
then do
P.spaces
vr <- parsec <|> return anyVersion
P.spaces
return (PackageVersionConstraint name vr)
else
pure (PackageVersionConstraint name (thisVersion ver))
thisPackageVersionConstraint :: PackageIdentifier -> PackageVersionConstraint
thisPackageVersionConstraint (PackageIdentifier pn vr) =
PackageVersionConstraint pn (thisVersion vr)
simplifyPackageVersionConstraint :: PackageVersionConstraint -> PackageVersionConstraint
simplifyPackageVersionConstraint (PackageVersionConstraint pn vr) =
PackageVersionConstraint pn (simplifyVersionRange vr)