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 _any this later earlier union intersect = fold
where
fold = cataVersionRange alg
alg (ThisVersionF v) = this v
alg (LaterVersionF v) = later v
alg (OrLaterVersionF v) = union (this v) (later v)
alg (EarlierVersionF v) = earlier v
alg (OrEarlierVersionF v) = union (this v) (earlier v)
alg (MajorBoundVersionF v) = fold (majorBound v)
alg (UnionVersionRangesF v1 v2) = union v1 v2
alg (IntersectVersionRangesF v1 v2) = intersect v1 v2
majorBound v = intersectVersionRanges
(orLaterVersion v)
(earlierVersion (majorUpperBound v))
normaliseVersionRange :: VersionRange -> VersionRange
normaliseVersionRange = hyloVersionRange embed projectVersionRange
where
embed (UnionVersionRangesF (ThisVersion v) (LaterVersion v')) | v == v' =
orLaterVersion v
embed (UnionVersionRangesF (LaterVersion v) (ThisVersion v')) | v == v' =
orLaterVersion v
embed (UnionVersionRangesF (ThisVersion v) (EarlierVersion v')) | v == v' =
orEarlierVersion v
embed (UnionVersionRangesF (EarlierVersion v) (ThisVersion v')) | v == v' =
orEarlierVersion v
embed vr = embedVersionRange vr
stripParensVersionRange :: VersionRange -> VersionRange
stripParensVersionRange = id
withinRange :: Version -> VersionRange -> Bool
withinRange v = foldVersionRange
True
(\v' -> v == v')
(\v' -> v > v')
(\v' -> v < v')
(||)
(&&)
isAnyVersion :: VersionRange -> Bool
isAnyVersion vr = case asVersionIntervals vr of
[(LowerBound v InclusiveBound, NoUpperBound)] -> v == version0
_ -> False
isAnyVersionLight :: VersionRange -> Bool
isAnyVersionLight (OrLaterVersion v) = v == version0
isAnyVersionLight _vr = False
isWildcardRange :: Version -> Version -> Bool
isWildcardRange ver1 ver2 = check (versionNumbers ver1) (versionNumbers ver2)
where check (n:[]) (m:[]) | n+1 == m = True
check (n:ns) (m:ms) | n == m = check ns ms
check _ _ = False
hasUpperBound :: VersionRange -> Bool
hasUpperBound = foldVersionRange
False
(const True)
(const False)
(const True)
(&&) (||)
hasLowerBound :: VersionRange -> Bool
hasLowerBound = foldVersionRange
False
(const True)
(const True)
(const False)
(&&) (||)