module Distribution.Types.VersionRange (
VersionRange,
anyVersion, noVersion,
thisVersion, notThisVersion,
laterVersion, earlierVersion,
orLaterVersion, orEarlierVersion,
unionVersionRanges, intersectVersionRanges,
withinVersion,
majorBoundVersion,
withinRange,
foldVersionRange,
normaliseVersionRange,
stripParensVersionRange,
hasUpperBound,
hasLowerBound,
VersionRangeF (..),
cataVersionRange,
anaVersionRange,
hyloVersionRange,
projectVersionRange,
embedVersionRange,
isAnyVersion,
isAnyVersionLight,
wildcardUpperBound,
majorUpperBound,
isWildcardRange,
versionRangeParser,
) where
import Distribution.Compat.Prelude
import Distribution.Types.Version
import Distribution.Types.VersionInterval
import Distribution.Types.VersionRange.Internal
import Prelude ()
foldVersionRange :: a
-> (Version -> a)
-> (Version -> a)
-> (Version -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> VersionRange -> a
foldVersionRange :: a
-> (Version -> a)
-> (Version -> a)
-> (Version -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> VersionRange
-> a
foldVersionRange a
_any Version -> a
this Version -> a
later Version -> a
earlier a -> a -> a
union a -> a -> a
intersect = VersionRange -> a
fold
where
fold :: VersionRange -> a
fold = (VersionRangeF a -> a) -> VersionRange -> a
forall a. (VersionRangeF a -> a) -> VersionRange -> a
cataVersionRange VersionRangeF a -> a
alg
alg :: VersionRangeF a -> a
alg (ThisVersionF Version
v) = Version -> a
this Version
v
alg (LaterVersionF Version
v) = Version -> a
later Version
v
alg (OrLaterVersionF Version
v) = a -> a -> a
union (Version -> a
this Version
v) (Version -> a
later Version
v)
alg (EarlierVersionF Version
v) = Version -> a
earlier Version
v
alg (OrEarlierVersionF Version
v) = a -> a -> a
union (Version -> a
this Version
v) (Version -> a
earlier Version
v)
alg (MajorBoundVersionF Version
v) = VersionRange -> a
fold (Version -> VersionRange
majorBound Version
v)
alg (UnionVersionRangesF a
v1 a
v2) = a -> a -> a
union a
v1 a
v2
alg (IntersectVersionRangesF a
v1 a
v2) = a -> a -> a
intersect a
v1 a
v2
majorBound :: Version -> VersionRange
majorBound Version
v = VersionRange -> VersionRange -> VersionRange
intersectVersionRanges
(Version -> VersionRange
orLaterVersion Version
v)
(Version -> VersionRange
earlierVersion (Version -> Version
majorUpperBound Version
v))
normaliseVersionRange :: VersionRange -> VersionRange
normaliseVersionRange :: VersionRange -> VersionRange
normaliseVersionRange = (VersionRangeF VersionRange -> VersionRange)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRange
hyloVersionRange VersionRangeF VersionRange -> VersionRange
embed VersionRange -> VersionRangeF VersionRange
projectVersionRange
where
embed :: VersionRangeF VersionRange -> VersionRange
embed (UnionVersionRangesF (ThisVersion Version
v) (LaterVersion Version
v')) | Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
v' =
Version -> VersionRange
orLaterVersion Version
v
embed (UnionVersionRangesF (LaterVersion Version
v) (ThisVersion Version
v')) | Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
v' =
Version -> VersionRange
orLaterVersion Version
v
embed (UnionVersionRangesF (ThisVersion Version
v) (EarlierVersion Version
v')) | Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
v' =
Version -> VersionRange
orEarlierVersion Version
v
embed (UnionVersionRangesF (EarlierVersion Version
v) (ThisVersion Version
v')) | Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
v' =
Version -> VersionRange
orEarlierVersion Version
v
embed VersionRangeF VersionRange
vr = VersionRangeF VersionRange -> VersionRange
embedVersionRange VersionRangeF VersionRange
vr
stripParensVersionRange :: VersionRange -> VersionRange
stripParensVersionRange :: VersionRange -> VersionRange
stripParensVersionRange = VersionRange -> VersionRange
forall a. a -> a
id
withinRange :: Version -> VersionRange -> Bool
withinRange :: Version -> VersionRange -> Bool
withinRange Version
v = Bool
-> (Version -> Bool)
-> (Version -> Bool)
-> (Version -> Bool)
-> (Bool -> Bool -> Bool)
-> (Bool -> Bool -> Bool)
-> VersionRange
-> Bool
forall a.
a
-> (Version -> a)
-> (Version -> a)
-> (Version -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> VersionRange
-> a
foldVersionRange
Bool
True
(\Version
v' -> Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
v')
(\Version
v' -> Version
v Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
> Version
v')
(\Version
v' -> Version
v Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
< Version
v')
Bool -> Bool -> Bool
(||)
Bool -> Bool -> Bool
(&&)
isAnyVersion :: VersionRange -> Bool
isAnyVersion :: VersionRange -> Bool
isAnyVersion VersionRange
vr = case VersionRange -> [VersionInterval]
asVersionIntervals VersionRange
vr of
[(LowerBound Version
v Bound
InclusiveBound, UpperBound
NoUpperBound)] -> Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
version0
[VersionInterval]
_ -> Bool
False
isAnyVersionLight :: VersionRange -> Bool
isAnyVersionLight :: VersionRange -> Bool
isAnyVersionLight (OrLaterVersion Version
v) = Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
version0
isAnyVersionLight VersionRange
_vr = Bool
False
isWildcardRange :: Version -> Version -> Bool
isWildcardRange :: Version -> Version -> Bool
isWildcardRange Version
ver1 Version
ver2 = [Int] -> [Int] -> Bool
forall a. (Eq a, Num a) => [a] -> [a] -> Bool
check (Version -> [Int]
versionNumbers Version
ver1) (Version -> [Int]
versionNumbers Version
ver2)
where check :: [a] -> [a] -> Bool
check (a
n:[]) (a
m:[]) | a
na -> a -> a
forall a. Num a => a -> a -> a
+a
1 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
m = Bool
True
check (a
n:[a]
ns) (a
m:[a]
ms) | a
n a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
m = [a] -> [a] -> Bool
check [a]
ns [a]
ms
check [a]
_ [a]
_ = Bool
False
hasUpperBound :: VersionRange -> Bool
hasUpperBound :: VersionRange -> Bool
hasUpperBound = Bool
-> (Version -> Bool)
-> (Version -> Bool)
-> (Version -> Bool)
-> (Bool -> Bool -> Bool)
-> (Bool -> Bool -> Bool)
-> VersionRange
-> Bool
forall a.
a
-> (Version -> a)
-> (Version -> a)
-> (Version -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> VersionRange
-> a
foldVersionRange
Bool
False
(Bool -> Version -> Bool
forall a b. a -> b -> a
const Bool
True)
(Bool -> Version -> Bool
forall a b. a -> b -> a
const Bool
False)
(Bool -> Version -> Bool
forall a b. a -> b -> a
const Bool
True)
Bool -> Bool -> Bool
(&&) Bool -> Bool -> Bool
(||)
hasLowerBound :: VersionRange -> Bool
hasLowerBound :: VersionRange -> Bool
hasLowerBound = Bool
-> (Version -> Bool)
-> (Version -> Bool)
-> (Version -> Bool)
-> (Bool -> Bool -> Bool)
-> (Bool -> Bool -> Bool)
-> VersionRange
-> Bool
forall a.
a
-> (Version -> a)
-> (Version -> a)
-> (Version -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> VersionRange
-> a
foldVersionRange
Bool
False
(Bool -> Version -> Bool
forall a b. a -> b -> a
const Bool
True)
(Bool -> Version -> Bool
forall a b. a -> b -> a
const Bool
True)
(Bool -> Version -> Bool
forall a b. a -> b -> a
const Bool
False)
Bool -> Bool -> Bool
(&&) Bool -> Bool -> Bool
(||)