{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | The only purpose of this module is to prevent the export of
-- 'VersionRange' constructors from
-- "Distribution.Types.VersionRange". To avoid creating orphan
-- instances, a lot of related code had to be moved here too.
module Distribution.Types.VersionRange.Internal
  ( VersionRange (..)
  , anyVersion
  , noVersion
  , thisVersion
  , notThisVersion
  , laterVersion
  , earlierVersion
  , orLaterVersion
  , orEarlierVersion
  , unionVersionRanges
  , intersectVersionRanges
  , withinVersion
  , majorBoundVersion
  , VersionRangeF (..)
  , projectVersionRange
  , embedVersionRange
  , cataVersionRange
  , anaVersionRange
  , hyloVersionRange
  , versionRangeParser
  , majorUpperBound
  , wildcardUpperBound
  ) where

import Distribution.Compat.Prelude
import Distribution.Types.Version
import Prelude ()

import Distribution.CabalSpecVersion
import Distribution.Parsec
import Distribution.Pretty
import Distribution.Utils.Generic (unsnoc)

import qualified Distribution.Compat.CharParsing as P
import qualified Distribution.Compat.DList as DList
import qualified Text.PrettyPrint as Disp

data VersionRange
  = ThisVersion Version -- = version
  | LaterVersion Version -- > version  (NB. not >=)
  | OrLaterVersion Version -- >= version
  | EarlierVersion Version -- < version
  | OrEarlierVersion Version -- <= version
  | MajorBoundVersion Version -- @^>= ver@ (same as >= ver && < MAJ(ver)+1)
  | UnionVersionRanges VersionRange VersionRange
  | IntersectVersionRanges VersionRange VersionRange
  deriving (Typeable VersionRange
Typeable VersionRange =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> VersionRange -> c VersionRange)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c VersionRange)
-> (VersionRange -> Constr)
-> (VersionRange -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c VersionRange))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c VersionRange))
-> ((forall b. Data b => b -> b) -> VersionRange -> VersionRange)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> VersionRange -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> VersionRange -> r)
-> (forall u. (forall d. Data d => d -> u) -> VersionRange -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> VersionRange -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange)
-> Data VersionRange
VersionRange -> Constr
VersionRange -> DataType
(forall b. Data b => b -> b) -> VersionRange -> VersionRange
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> VersionRange -> u
forall u. (forall d. Data d => d -> u) -> VersionRange -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRange -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRange -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionRange -> m VersionRange
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionRange -> m VersionRange
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionRange
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionRange -> c VersionRange
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionRange)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionRange)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionRange -> c VersionRange
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionRange -> c VersionRange
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionRange
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c VersionRange
$ctoConstr :: VersionRange -> Constr
toConstr :: VersionRange -> Constr
$cdataTypeOf :: VersionRange -> DataType
dataTypeOf :: VersionRange -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionRange)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c VersionRange)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionRange)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c VersionRange)
$cgmapT :: (forall b. Data b => b -> b) -> VersionRange -> VersionRange
gmapT :: (forall b. Data b => b -> b) -> VersionRange -> VersionRange
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRange -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRange -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRange -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRange -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> VersionRange -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> VersionRange -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> VersionRange -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> VersionRange -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionRange -> m VersionRange
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VersionRange -> m VersionRange
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionRange -> m VersionRange
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionRange -> m VersionRange
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionRange -> m VersionRange
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VersionRange -> m VersionRange
Data, VersionRange -> VersionRange -> Bool
(VersionRange -> VersionRange -> Bool)
-> (VersionRange -> VersionRange -> Bool) -> Eq VersionRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VersionRange -> VersionRange -> Bool
== :: VersionRange -> VersionRange -> Bool
$c/= :: VersionRange -> VersionRange -> Bool
/= :: VersionRange -> VersionRange -> Bool
Eq, Eq VersionRange
Eq VersionRange =>
(VersionRange -> VersionRange -> Ordering)
-> (VersionRange -> VersionRange -> Bool)
-> (VersionRange -> VersionRange -> Bool)
-> (VersionRange -> VersionRange -> Bool)
-> (VersionRange -> VersionRange -> Bool)
-> (VersionRange -> VersionRange -> VersionRange)
-> (VersionRange -> VersionRange -> VersionRange)
-> Ord VersionRange
VersionRange -> VersionRange -> Bool
VersionRange -> VersionRange -> Ordering
VersionRange -> VersionRange -> VersionRange
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: VersionRange -> VersionRange -> Ordering
compare :: VersionRange -> VersionRange -> Ordering
$c< :: VersionRange -> VersionRange -> Bool
< :: VersionRange -> VersionRange -> Bool
$c<= :: VersionRange -> VersionRange -> Bool
<= :: VersionRange -> VersionRange -> Bool
$c> :: VersionRange -> VersionRange -> Bool
> :: VersionRange -> VersionRange -> Bool
$c>= :: VersionRange -> VersionRange -> Bool
>= :: VersionRange -> VersionRange -> Bool
$cmax :: VersionRange -> VersionRange -> VersionRange
max :: VersionRange -> VersionRange -> VersionRange
$cmin :: VersionRange -> VersionRange -> VersionRange
min :: VersionRange -> VersionRange -> VersionRange
Ord, (forall x. VersionRange -> Rep VersionRange x)
-> (forall x. Rep VersionRange x -> VersionRange)
-> Generic VersionRange
forall x. Rep VersionRange x -> VersionRange
forall x. VersionRange -> Rep VersionRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. VersionRange -> Rep VersionRange x
from :: forall x. VersionRange -> Rep VersionRange x
$cto :: forall x. Rep VersionRange x -> VersionRange
to :: forall x. Rep VersionRange x -> VersionRange
Generic, ReadPrec [VersionRange]
ReadPrec VersionRange
Int -> ReadS VersionRange
ReadS [VersionRange]
(Int -> ReadS VersionRange)
-> ReadS [VersionRange]
-> ReadPrec VersionRange
-> ReadPrec [VersionRange]
-> Read VersionRange
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS VersionRange
readsPrec :: Int -> ReadS VersionRange
$creadList :: ReadS [VersionRange]
readList :: ReadS [VersionRange]
$creadPrec :: ReadPrec VersionRange
readPrec :: ReadPrec VersionRange
$creadListPrec :: ReadPrec [VersionRange]
readListPrec :: ReadPrec [VersionRange]
Read, Int -> VersionRange -> ShowS
[VersionRange] -> ShowS
VersionRange -> String
(Int -> VersionRange -> ShowS)
-> (VersionRange -> String)
-> ([VersionRange] -> ShowS)
-> Show VersionRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VersionRange -> ShowS
showsPrec :: Int -> VersionRange -> ShowS
$cshow :: VersionRange -> String
show :: VersionRange -> String
$cshowList :: [VersionRange] -> ShowS
showList :: [VersionRange] -> ShowS
Show, Typeable)

instance Binary VersionRange
instance Structured VersionRange
instance NFData VersionRange where rnf :: VersionRange -> ()
rnf = VersionRange -> ()
forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

-- | The version range @-any@. That is, a version range containing all
-- versions.
--
-- > withinRange v anyVersion = True
anyVersion :: VersionRange
anyVersion :: VersionRange
anyVersion = Version -> VersionRange
OrLaterVersion ([Int] -> Version
mkVersion [Int
0])

-- | The empty version range @-none@, that is a version range containing no versions.
--
-- This can be constructed using any unsatisfiable version range expression,
-- for example @< 0@.
--
-- > withinRange v noVersion = False
noVersion :: VersionRange
noVersion :: VersionRange
noVersion = Version -> VersionRange
EarlierVersion ([Int] -> Version
mkVersion [Int
0])

-- | The version range @== v@.
--
-- > withinRange v' (thisVersion v) = v' == v
thisVersion :: Version -> VersionRange
thisVersion :: Version -> VersionRange
thisVersion = Version -> VersionRange
ThisVersion

-- | The version range @/= v@.
--
-- > withinRange v' (notThisVersion v) = v' /= v
notThisVersion :: Version -> VersionRange
notThisVersion :: Version -> VersionRange
notThisVersion Version
v = VersionRange -> VersionRange -> VersionRange
UnionVersionRanges (Version -> VersionRange
EarlierVersion Version
v) (Version -> VersionRange
LaterVersion Version
v)

-- | The version range @> v@.
--
-- > withinRange v' (laterVersion v) = v' > v
laterVersion :: Version -> VersionRange
laterVersion :: Version -> VersionRange
laterVersion = Version -> VersionRange
LaterVersion

-- | The version range @>= v@.
--
-- > withinRange v' (orLaterVersion v) = v' >= v
orLaterVersion :: Version -> VersionRange
orLaterVersion :: Version -> VersionRange
orLaterVersion = Version -> VersionRange
OrLaterVersion

-- | The version range @< v@.
--
-- > withinRange v' (earlierVersion v) = v' < v
earlierVersion :: Version -> VersionRange
earlierVersion :: Version -> VersionRange
earlierVersion = Version -> VersionRange
EarlierVersion

-- | The version range @<= v@.
--
-- > withinRange v' (orEarlierVersion v) = v' <= v
orEarlierVersion :: Version -> VersionRange
orEarlierVersion :: Version -> VersionRange
orEarlierVersion = Version -> VersionRange
OrEarlierVersion

-- | The version range @vr1 || vr2@.
--
-- >   withinRange v' (unionVersionRanges vr1 vr2)
-- > = withinRange v' vr1 || withinRange v' vr2
unionVersionRanges :: VersionRange -> VersionRange -> VersionRange
unionVersionRanges :: VersionRange -> VersionRange -> VersionRange
unionVersionRanges = VersionRange -> VersionRange -> VersionRange
UnionVersionRanges

-- | The version range @vr1 && vr2@.
--
-- >   withinRange v' (intersectVersionRanges vr1 vr2)
-- > = withinRange v' vr1 && withinRange v' vr2
intersectVersionRanges :: VersionRange -> VersionRange -> VersionRange
intersectVersionRanges :: VersionRange -> VersionRange -> VersionRange
intersectVersionRanges = VersionRange -> VersionRange -> VersionRange
IntersectVersionRanges

-- | The version range @== v.*@.
--
-- For example, for version @1.2@, the version range @== 1.2.*@ is the same as
-- @>= 1.2 && < 1.3@.
--
-- > withinRange v' (withinVersion v) = v' >= v && v' < upper v
-- >   where
-- >     upper (Version lower t) = Version (init lower ++ [last lower + 1]) t
withinVersion :: Version -> VersionRange
withinVersion :: Version -> VersionRange
withinVersion Version
v =
  VersionRange -> VersionRange -> VersionRange
intersectVersionRanges
    (Version -> VersionRange
orLaterVersion Version
v)
    (Version -> VersionRange
earlierVersion (Version -> Version
wildcardUpperBound Version
v))

-- | The version range @^>= v@.
--
-- For example, for version @1.2.3.4@, the version range @^>= 1.2.3.4@
-- is the same as @>= 1.2.3.4 && < 1.3@.
--
-- Note that @^>= 1@ is equivalent to @>= 1 && < 1.1@.
--
-- @since 2.0.0.2
majorBoundVersion :: Version -> VersionRange
majorBoundVersion :: Version -> VersionRange
majorBoundVersion = Version -> VersionRange
MajorBoundVersion

-- | F-Algebra of 'VersionRange'. See 'cataVersionRange'.
--
-- @since 2.2
data VersionRangeF a
  = -- | @== version@.
    ThisVersionF Version
  | -- | @>  version@.   NB: not @>=@
    LaterVersionF Version
  | -- | @>= version@.
    OrLaterVersionF Version
  | -- | @<  version@.
    EarlierVersionF Version
  | -- | @<= version@.
    OrEarlierVersionF Version
  | -- | @^>= version@, same as @>= version && < MAJ(version)+1@.
    MajorBoundVersionF Version
  | -- | @||@.
    UnionVersionRangesF a a
  | -- | @&&@.
    IntersectVersionRangesF a a
  deriving
    ( Typeable (VersionRangeF a)
Typeable (VersionRangeF a) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> VersionRangeF a -> c (VersionRangeF a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (VersionRangeF a))
-> (VersionRangeF a -> Constr)
-> (VersionRangeF a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (VersionRangeF a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (VersionRangeF a)))
-> ((forall b. Data b => b -> b)
    -> VersionRangeF a -> VersionRangeF a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> VersionRangeF a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> VersionRangeF a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> VersionRangeF a -> m (VersionRangeF a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> VersionRangeF a -> m (VersionRangeF a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> VersionRangeF a -> m (VersionRangeF a))
-> Data (VersionRangeF a)
VersionRangeF a -> Constr
VersionRangeF a -> DataType
(forall b. Data b => b -> b) -> VersionRangeF a -> VersionRangeF a
forall a. Data a => Typeable (VersionRangeF a)
forall a. Data a => VersionRangeF a -> Constr
forall a. Data a => VersionRangeF a -> DataType
forall a.
Data a =>
(forall b. Data b => b -> b) -> VersionRangeF a -> VersionRangeF a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> VersionRangeF a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> VersionRangeF a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VersionRangeF a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionRangeF a -> c (VersionRangeF a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (VersionRangeF a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VersionRangeF a))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> VersionRangeF a -> u
forall u. (forall d. Data d => d -> u) -> VersionRangeF a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VersionRangeF a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionRangeF a -> c (VersionRangeF a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (VersionRangeF a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VersionRangeF a))
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionRangeF a -> c (VersionRangeF a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VersionRangeF a -> c (VersionRangeF a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VersionRangeF a)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VersionRangeF a)
$ctoConstr :: forall a. Data a => VersionRangeF a -> Constr
toConstr :: VersionRangeF a -> Constr
$cdataTypeOf :: forall a. Data a => VersionRangeF a -> DataType
dataTypeOf :: VersionRangeF a -> DataType
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (VersionRangeF a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (VersionRangeF a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VersionRangeF a))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VersionRangeF a))
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> VersionRangeF a -> VersionRangeF a
gmapT :: (forall b. Data b => b -> b) -> VersionRangeF a -> VersionRangeF a
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> VersionRangeF a -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> VersionRangeF a -> [u]
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> VersionRangeF a -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> VersionRangeF a -> u
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> VersionRangeF a -> m (VersionRangeF a)
Data
    , VersionRangeF a -> VersionRangeF a -> Bool
(VersionRangeF a -> VersionRangeF a -> Bool)
-> (VersionRangeF a -> VersionRangeF a -> Bool)
-> Eq (VersionRangeF a)
forall a. Eq a => VersionRangeF a -> VersionRangeF a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => VersionRangeF a -> VersionRangeF a -> Bool
== :: VersionRangeF a -> VersionRangeF a -> Bool
$c/= :: forall a. Eq a => VersionRangeF a -> VersionRangeF a -> Bool
/= :: VersionRangeF a -> VersionRangeF a -> Bool
Eq
    , (forall x. VersionRangeF a -> Rep (VersionRangeF a) x)
-> (forall x. Rep (VersionRangeF a) x -> VersionRangeF a)
-> Generic (VersionRangeF a)
forall x. Rep (VersionRangeF a) x -> VersionRangeF a
forall x. VersionRangeF a -> Rep (VersionRangeF a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (VersionRangeF a) x -> VersionRangeF a
forall a x. VersionRangeF a -> Rep (VersionRangeF a) x
$cfrom :: forall a x. VersionRangeF a -> Rep (VersionRangeF a) x
from :: forall x. VersionRangeF a -> Rep (VersionRangeF a) x
$cto :: forall a x. Rep (VersionRangeF a) x -> VersionRangeF a
to :: forall x. Rep (VersionRangeF a) x -> VersionRangeF a
Generic
    , ReadPrec [VersionRangeF a]
ReadPrec (VersionRangeF a)
Int -> ReadS (VersionRangeF a)
ReadS [VersionRangeF a]
(Int -> ReadS (VersionRangeF a))
-> ReadS [VersionRangeF a]
-> ReadPrec (VersionRangeF a)
-> ReadPrec [VersionRangeF a]
-> Read (VersionRangeF a)
forall a. Read a => ReadPrec [VersionRangeF a]
forall a. Read a => ReadPrec (VersionRangeF a)
forall a. Read a => Int -> ReadS (VersionRangeF a)
forall a. Read a => ReadS [VersionRangeF a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (VersionRangeF a)
readsPrec :: Int -> ReadS (VersionRangeF a)
$creadList :: forall a. Read a => ReadS [VersionRangeF a]
readList :: ReadS [VersionRangeF a]
$creadPrec :: forall a. Read a => ReadPrec (VersionRangeF a)
readPrec :: ReadPrec (VersionRangeF a)
$creadListPrec :: forall a. Read a => ReadPrec [VersionRangeF a]
readListPrec :: ReadPrec [VersionRangeF a]
Read
    , Int -> VersionRangeF a -> ShowS
[VersionRangeF a] -> ShowS
VersionRangeF a -> String
(Int -> VersionRangeF a -> ShowS)
-> (VersionRangeF a -> String)
-> ([VersionRangeF a] -> ShowS)
-> Show (VersionRangeF a)
forall a. Show a => Int -> VersionRangeF a -> ShowS
forall a. Show a => [VersionRangeF a] -> ShowS
forall a. Show a => VersionRangeF a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> VersionRangeF a -> ShowS
showsPrec :: Int -> VersionRangeF a -> ShowS
$cshow :: forall a. Show a => VersionRangeF a -> String
show :: VersionRangeF a -> String
$cshowList :: forall a. Show a => [VersionRangeF a] -> ShowS
showList :: [VersionRangeF a] -> ShowS
Show
    , Typeable
    , (forall a b. (a -> b) -> VersionRangeF a -> VersionRangeF b)
-> (forall a b. a -> VersionRangeF b -> VersionRangeF a)
-> Functor VersionRangeF
forall a b. a -> VersionRangeF b -> VersionRangeF a
forall a b. (a -> b) -> VersionRangeF a -> VersionRangeF b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> VersionRangeF a -> VersionRangeF b
fmap :: forall a b. (a -> b) -> VersionRangeF a -> VersionRangeF b
$c<$ :: forall a b. a -> VersionRangeF b -> VersionRangeF a
<$ :: forall a b. a -> VersionRangeF b -> VersionRangeF a
Functor
    , (forall m. Monoid m => VersionRangeF m -> m)
-> (forall m a. Monoid m => (a -> m) -> VersionRangeF a -> m)
-> (forall m a. Monoid m => (a -> m) -> VersionRangeF a -> m)
-> (forall a b. (a -> b -> b) -> b -> VersionRangeF a -> b)
-> (forall a b. (a -> b -> b) -> b -> VersionRangeF a -> b)
-> (forall b a. (b -> a -> b) -> b -> VersionRangeF a -> b)
-> (forall b a. (b -> a -> b) -> b -> VersionRangeF a -> b)
-> (forall a. (a -> a -> a) -> VersionRangeF a -> a)
-> (forall a. (a -> a -> a) -> VersionRangeF a -> a)
-> (forall a. VersionRangeF a -> [a])
-> (forall a. VersionRangeF a -> Bool)
-> (forall a. VersionRangeF a -> Int)
-> (forall a. Eq a => a -> VersionRangeF a -> Bool)
-> (forall a. Ord a => VersionRangeF a -> a)
-> (forall a. Ord a => VersionRangeF a -> a)
-> (forall a. Num a => VersionRangeF a -> a)
-> (forall a. Num a => VersionRangeF a -> a)
-> Foldable VersionRangeF
forall a. Eq a => a -> VersionRangeF a -> Bool
forall a. Num a => VersionRangeF a -> a
forall a. Ord a => VersionRangeF a -> a
forall m. Monoid m => VersionRangeF m -> m
forall a. VersionRangeF a -> Bool
forall a. VersionRangeF a -> Int
forall a. VersionRangeF a -> [a]
forall a. (a -> a -> a) -> VersionRangeF a -> a
forall m a. Monoid m => (a -> m) -> VersionRangeF a -> m
forall b a. (b -> a -> b) -> b -> VersionRangeF a -> b
forall a b. (a -> b -> b) -> b -> VersionRangeF a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => VersionRangeF m -> m
fold :: forall m. Monoid m => VersionRangeF m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> VersionRangeF a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> VersionRangeF a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> VersionRangeF a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> VersionRangeF a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> VersionRangeF a -> b
foldr :: forall a b. (a -> b -> b) -> b -> VersionRangeF a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> VersionRangeF a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> VersionRangeF a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> VersionRangeF a -> b
foldl :: forall b a. (b -> a -> b) -> b -> VersionRangeF a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> VersionRangeF a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> VersionRangeF a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> VersionRangeF a -> a
foldr1 :: forall a. (a -> a -> a) -> VersionRangeF a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> VersionRangeF a -> a
foldl1 :: forall a. (a -> a -> a) -> VersionRangeF a -> a
$ctoList :: forall a. VersionRangeF a -> [a]
toList :: forall a. VersionRangeF a -> [a]
$cnull :: forall a. VersionRangeF a -> Bool
null :: forall a. VersionRangeF a -> Bool
$clength :: forall a. VersionRangeF a -> Int
length :: forall a. VersionRangeF a -> Int
$celem :: forall a. Eq a => a -> VersionRangeF a -> Bool
elem :: forall a. Eq a => a -> VersionRangeF a -> Bool
$cmaximum :: forall a. Ord a => VersionRangeF a -> a
maximum :: forall a. Ord a => VersionRangeF a -> a
$cminimum :: forall a. Ord a => VersionRangeF a -> a
minimum :: forall a. Ord a => VersionRangeF a -> a
$csum :: forall a. Num a => VersionRangeF a -> a
sum :: forall a. Num a => VersionRangeF a -> a
$cproduct :: forall a. Num a => VersionRangeF a -> a
product :: forall a. Num a => VersionRangeF a -> a
Foldable
    , Functor VersionRangeF
Foldable VersionRangeF
(Functor VersionRangeF, Foldable VersionRangeF) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> VersionRangeF a -> f (VersionRangeF b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    VersionRangeF (f a) -> f (VersionRangeF a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> VersionRangeF a -> m (VersionRangeF b))
-> (forall (m :: * -> *) a.
    Monad m =>
    VersionRangeF (m a) -> m (VersionRangeF a))
-> Traversable VersionRangeF
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
VersionRangeF (m a) -> m (VersionRangeF a)
forall (f :: * -> *) a.
Applicative f =>
VersionRangeF (f a) -> f (VersionRangeF a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> VersionRangeF a -> m (VersionRangeF b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> VersionRangeF a -> f (VersionRangeF b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> VersionRangeF a -> f (VersionRangeF b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> VersionRangeF a -> f (VersionRangeF b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
VersionRangeF (f a) -> f (VersionRangeF a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
VersionRangeF (f a) -> f (VersionRangeF a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> VersionRangeF a -> m (VersionRangeF b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> VersionRangeF a -> m (VersionRangeF b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
VersionRangeF (m a) -> m (VersionRangeF a)
sequence :: forall (m :: * -> *) a.
Monad m =>
VersionRangeF (m a) -> m (VersionRangeF a)
Traversable
    )

-- | Generic destructor for 'VersionRange'.
--
-- @since 2.2
projectVersionRange :: VersionRange -> VersionRangeF VersionRange
projectVersionRange :: VersionRange -> VersionRangeF VersionRange
projectVersionRange (ThisVersion Version
v) = Version -> VersionRangeF VersionRange
forall a. Version -> VersionRangeF a
ThisVersionF Version
v
projectVersionRange (LaterVersion Version
v) = Version -> VersionRangeF VersionRange
forall a. Version -> VersionRangeF a
LaterVersionF Version
v
projectVersionRange (OrLaterVersion Version
v) = Version -> VersionRangeF VersionRange
forall a. Version -> VersionRangeF a
OrLaterVersionF Version
v
projectVersionRange (EarlierVersion Version
v) = Version -> VersionRangeF VersionRange
forall a. Version -> VersionRangeF a
EarlierVersionF Version
v
projectVersionRange (OrEarlierVersion Version
v) = Version -> VersionRangeF VersionRange
forall a. Version -> VersionRangeF a
OrEarlierVersionF Version
v
projectVersionRange (MajorBoundVersion Version
v) = Version -> VersionRangeF VersionRange
forall a. Version -> VersionRangeF a
MajorBoundVersionF Version
v
projectVersionRange (UnionVersionRanges VersionRange
a VersionRange
b) = VersionRange -> VersionRange -> VersionRangeF VersionRange
forall a. a -> a -> VersionRangeF a
UnionVersionRangesF VersionRange
a VersionRange
b
projectVersionRange (IntersectVersionRanges VersionRange
a VersionRange
b) = VersionRange -> VersionRange -> VersionRangeF VersionRange
forall a. a -> a -> VersionRangeF a
IntersectVersionRangesF VersionRange
a VersionRange
b

-- | Fold 'VersionRange'.
--
-- @since 2.2
cataVersionRange :: (VersionRangeF a -> a) -> VersionRange -> a
cataVersionRange :: forall a. (VersionRangeF a -> a) -> VersionRange -> a
cataVersionRange VersionRangeF a -> a
f = VersionRange -> a
c where c :: VersionRange -> a
c = VersionRangeF a -> a
f (VersionRangeF a -> a)
-> (VersionRange -> VersionRangeF a) -> VersionRange -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VersionRange -> a)
-> VersionRangeF VersionRange -> VersionRangeF a
forall a b. (a -> b) -> VersionRangeF a -> VersionRangeF b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap VersionRange -> a
c (VersionRangeF VersionRange -> VersionRangeF a)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRangeF a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionRange -> VersionRangeF VersionRange
projectVersionRange

-- | Generic constructor for 'VersionRange'.
--
-- @since 2.2
embedVersionRange :: VersionRangeF VersionRange -> VersionRange
embedVersionRange :: VersionRangeF VersionRange -> VersionRange
embedVersionRange (ThisVersionF Version
v) = Version -> VersionRange
ThisVersion Version
v
embedVersionRange (LaterVersionF Version
v) = Version -> VersionRange
LaterVersion Version
v
embedVersionRange (OrLaterVersionF Version
v) = Version -> VersionRange
OrLaterVersion Version
v
embedVersionRange (EarlierVersionF Version
v) = Version -> VersionRange
EarlierVersion Version
v
embedVersionRange (OrEarlierVersionF Version
v) = Version -> VersionRange
OrEarlierVersion Version
v
embedVersionRange (MajorBoundVersionF Version
v) = Version -> VersionRange
MajorBoundVersion Version
v
embedVersionRange (UnionVersionRangesF VersionRange
a VersionRange
b) = VersionRange -> VersionRange -> VersionRange
UnionVersionRanges VersionRange
a VersionRange
b
embedVersionRange (IntersectVersionRangesF VersionRange
a VersionRange
b) = VersionRange -> VersionRange -> VersionRange
IntersectVersionRanges VersionRange
a VersionRange
b

-- | Unfold 'VersionRange'.
--
-- @since 2.2
anaVersionRange :: (a -> VersionRangeF a) -> a -> VersionRange
anaVersionRange :: forall a. (a -> VersionRangeF a) -> a -> VersionRange
anaVersionRange a -> VersionRangeF a
g = a -> VersionRange
a where a :: a -> VersionRange
a = VersionRangeF VersionRange -> VersionRange
embedVersionRange (VersionRangeF VersionRange -> VersionRange)
-> (a -> VersionRangeF VersionRange) -> a -> VersionRange
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> VersionRange)
-> VersionRangeF a -> VersionRangeF VersionRange
forall a b. (a -> b) -> VersionRangeF a -> VersionRangeF b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> VersionRange
a (VersionRangeF a -> VersionRangeF VersionRange)
-> (a -> VersionRangeF a) -> a -> VersionRangeF VersionRange
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> VersionRangeF a
g

-- | Refold 'VersionRange'.
--
-- @since 2.2
hyloVersionRange
  :: (VersionRangeF VersionRange -> VersionRange)
  -> (VersionRange -> VersionRangeF VersionRange)
  -> VersionRange
  -> VersionRange
hyloVersionRange :: (VersionRangeF VersionRange -> VersionRange)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRange
hyloVersionRange VersionRangeF VersionRange -> VersionRange
f VersionRange -> VersionRangeF VersionRange
g = VersionRange -> VersionRange
h where h :: VersionRange -> VersionRange
h = VersionRangeF VersionRange -> VersionRange
f (VersionRangeF VersionRange -> VersionRange)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRange
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VersionRange -> VersionRange)
-> VersionRangeF VersionRange -> VersionRangeF VersionRange
forall a b. (a -> b) -> VersionRangeF a -> VersionRangeF b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap VersionRange -> VersionRange
h (VersionRangeF VersionRange -> VersionRangeF VersionRange)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRangeF VersionRange
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionRange -> VersionRangeF VersionRange
g

-------------------------------------------------------------------------------
-- Parsec & Pretty
-------------------------------------------------------------------------------

-- |
--
-- >>> fmap pretty (simpleParsec' CabalSpecV1_6 "== 3.2.*" :: Maybe VersionRange)
-- Just >=3.2 && <3.3
--
-- >>> fmap (prettyVersioned CabalSpecV1_6) (simpleParsec' CabalSpecV1_6 "== 3.2.*" :: Maybe VersionRange)
-- Just ==3.2.*
--
-- >>> fmap pretty (simpleParsec' CabalSpecV1_6 "-any" :: Maybe VersionRange)
-- Just >=0
--
-- >>> fmap (prettyVersioned CabalSpecV1_6) (simpleParsec' CabalSpecV1_6 "-any" :: Maybe VersionRange)
-- Just >=0
instance Pretty VersionRange where
  pretty :: VersionRange -> Doc
pretty = CabalSpecVersion -> VersionRange -> Doc
forall a. Pretty a => CabalSpecVersion -> a -> Doc
prettyVersioned CabalSpecVersion
cabalSpecLatest

  prettyVersioned :: CabalSpecVersion -> VersionRange -> Doc
prettyVersioned CabalSpecVersion
csv
    | CabalSpecVersion
csv CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
> CabalSpecVersion
CabalSpecV1_6 = VersionRange -> Doc
prettyVersionRange
    | Bool
otherwise = VersionRange -> Doc
prettyVersionRange16

prettyVersionRange :: VersionRange -> Disp.Doc
prettyVersionRange :: VersionRange -> Doc
prettyVersionRange VersionRange
vr = (VersionRangeF (Int -> Doc) -> Int -> Doc)
-> VersionRange -> Int -> Doc
forall a. (VersionRangeF a -> a) -> VersionRange -> a
cataVersionRange VersionRangeF (Int -> Doc) -> Int -> Doc
alg VersionRange
vr Int
0
  where
    alg :: VersionRangeF (Int -> Disp.Doc) -> Int -> Disp.Doc
    alg :: VersionRangeF (Int -> Doc) -> Int -> Doc
alg (ThisVersionF Version
v) Int
_ = String -> Doc
Disp.text String
"==" Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
v
    alg (LaterVersionF Version
v) Int
_ = String -> Doc
Disp.text String
">" Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
v
    alg (OrLaterVersionF Version
v) Int
_ = String -> Doc
Disp.text String
">=" Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
v
    alg (EarlierVersionF Version
v) Int
_ = String -> Doc
Disp.text String
"<" Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
v
    alg (OrEarlierVersionF Version
v) Int
_ = String -> Doc
Disp.text String
"<=" Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
v
    alg (MajorBoundVersionF Version
v) Int
_ = String -> Doc
Disp.text String
"^>=" Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
v
    alg (UnionVersionRangesF Int -> Doc
r1 Int -> Doc
r2) Int
d =
      Bool -> Doc -> Doc
parens (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0) (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$
        Int -> Doc
r1 Int
1 Doc -> Doc -> Doc
<+> String -> Doc
Disp.text String
"||" Doc -> Doc -> Doc
<+> Int -> Doc
r2 Int
0
    alg (IntersectVersionRangesF Int -> Doc
r1 Int -> Doc
r2) Int
d =
      Bool -> Doc -> Doc
parens (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1) (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$
        Int -> Doc
r1 Int
2 Doc -> Doc -> Doc
<+> String -> Doc
Disp.text String
"&&" Doc -> Doc -> Doc
<+> Int -> Doc
r2 Int
1

    parens :: Bool -> Doc -> Doc
parens Bool
True = Doc -> Doc
Disp.parens
    parens Bool
False = Doc -> Doc
forall a. a -> a
id

-- | Don't use && and || operators. If possible.
prettyVersionRange16 :: VersionRange -> Disp.Doc
prettyVersionRange16 :: VersionRange -> Doc
prettyVersionRange16 (IntersectVersionRanges (OrLaterVersion Version
v) (EarlierVersion Version
u))
  | Version
u Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version -> Version
wildcardUpperBound Version
v =
      String -> Doc
Disp.text String
"==" Doc -> Doc -> Doc
<<>> Version -> Doc
dispWild Version
v
  where
    dispWild :: Version -> Doc
dispWild Version
ver =
      [Doc] -> Doc
Disp.hcat
        ( Doc -> [Doc] -> [Doc]
Disp.punctuate
            (Char -> Doc
Disp.char Char
'.')
            ((Int -> Doc) -> [Int] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Doc
Disp.int ([Int] -> [Doc]) -> [Int] -> [Doc]
forall a b. (a -> b) -> a -> b
$ Version -> [Int]
versionNumbers Version
ver)
        )
        Doc -> Doc -> Doc
<<>> String -> Doc
Disp.text String
".*"
prettyVersionRange16 VersionRange
vr = VersionRange -> Doc
prettyVersionRange VersionRange
vr

-- |
--
-- >>> simpleParsec "^>= 3.4" :: Maybe VersionRange
-- Just (MajorBoundVersion (mkVersion [3,4]))
--
-- Small history:
--
-- @-any@ and @-none@ removed in 3.4
-- Use @>=0@ and @<0@ instead.
--
-- >>> map (`simpleParsec'` "-none") [CabalSpecV3_0, CabalSpecV3_4] :: [Maybe VersionRange]
-- [Just (EarlierVersion (mkVersion [0])),Nothing]
--
-- Set operations are introduced in 3.0
--
-- >>> map (`simpleParsec'` "^>= { 1.2 , 1.3 }") [CabalSpecV2_4, CabalSpecV3_0] :: [Maybe VersionRange]
-- [Nothing,Just (UnionVersionRanges (MajorBoundVersion (mkVersion [1,2])) (MajorBoundVersion (mkVersion [1,3])))]
--
-- @^>=@ is introduced in 2.0
--
-- >>> map (`simpleParsec'` "^>=1.2") [CabalSpecV1_24, CabalSpecV2_0] :: [Maybe VersionRange]
-- [Nothing,Just (MajorBoundVersion (mkVersion [1,2]))]
--
-- @-none@ is introduced in 1.22
--
-- >>> map (`simpleParsec'` "-none") [CabalSpecV1_20, CabalSpecV1_22] :: [Maybe VersionRange]
-- [Nothing,Just (EarlierVersion (mkVersion [0]))]
--
-- Operators are introduced in 1.8. Issues only a warning.
--
-- >>> map (`simpleParsecW'` "== 1 || ==2") [CabalSpecV1_6, CabalSpecV1_8] :: [Maybe VersionRange]
-- [Nothing,Just (UnionVersionRanges (ThisVersion (mkVersion [1])) (ThisVersion (mkVersion [2])))]
--
-- Wild-version ranges are introduced in 1.6. Issues only a warning.
--
-- >>> map (`simpleParsecW'` "== 1.2.*") [CabalSpecV1_4, CabalSpecV1_6] :: [Maybe VersionRange]
-- [Nothing,Just (IntersectVersionRanges (OrLaterVersion (mkVersion [1,2])) (EarlierVersion (mkVersion [1,3])))]
instance Parsec VersionRange where
  parsec :: forall (m :: * -> *). CabalParsing m => m VersionRange
parsec = m CabalSpecVersion
forall (m :: * -> *). CabalParsing m => m CabalSpecVersion
askCabalSpecVersion m CabalSpecVersion
-> (CabalSpecVersion -> m VersionRange) -> m VersionRange
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m Int -> CabalSpecVersion -> m VersionRange
forall (m :: * -> *).
CabalParsing m =>
m Int -> CabalSpecVersion -> m VersionRange
versionRangeParser m Int
forall (m :: * -> *). CabalParsing m => m Int
versionDigitParser

-- | 'VersionRange' parser parametrised by version digit parser.
--
-- - 'versionDigitParser' is used for all 'VersionRange'.
-- - 'P.integral' is used for backward-compat @pkgconfig-depends@
--   versions, 'PkgConfigVersionRange'.
--
-- @since 3.0
versionRangeParser :: forall m. CabalParsing m => m Int -> CabalSpecVersion -> m VersionRange
versionRangeParser :: forall (m :: * -> *).
CabalParsing m =>
m Int -> CabalSpecVersion -> m VersionRange
versionRangeParser m Int
digitParser CabalSpecVersion
csv = m VersionRange
expr
  where
    expr :: m VersionRange
expr = do
      m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
      VersionRange
t <- m VersionRange
term
      m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
      ( do
          String
_ <- String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
P.string String
"||"
          m ()
checkOp
          m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
          VersionRange
e <- m VersionRange
expr
          VersionRange -> m VersionRange
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (VersionRange -> VersionRange -> VersionRange
unionVersionRanges VersionRange
t VersionRange
e)
          m VersionRange -> m VersionRange -> m VersionRange
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> VersionRange -> m VersionRange
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return VersionRange
t
        )
    term :: m VersionRange
term = do
      VersionRange
f <- m VersionRange
factor
      m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
      ( do
          String
_ <- String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
P.string String
"&&"
          m ()
checkOp
          m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
          VersionRange
t <- m VersionRange
term
          VersionRange -> m VersionRange
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (VersionRange -> VersionRange -> VersionRange
intersectVersionRanges VersionRange
f VersionRange
t)
          m VersionRange -> m VersionRange -> m VersionRange
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> VersionRange -> m VersionRange
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return VersionRange
f
        )
    factor :: m VersionRange
factor = m VersionRange -> m VersionRange
forall {m :: * -> *} {a}. (Monad m, CharParsing m) => m a -> m a
parens m VersionRange
expr m VersionRange -> m VersionRange -> m VersionRange
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m VersionRange
prim

    prim :: m VersionRange
prim = do
      String
op <- (Char -> Bool) -> m String
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch1 Char -> Bool
isOpChar m String -> String -> m String
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
P.<?> String
"operator"
      case String
op of
        String
"-" -> VersionRange
anyVersion VersionRange -> m String -> m VersionRange
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
P.string String
"any" m VersionRange -> m VersionRange -> m VersionRange
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
P.string String
"none" m String -> m VersionRange -> m VersionRange
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m VersionRange
noVersion'
        String
"==" -> do
          m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
          ( do
              (Bool
wild, Version
v) <- m (Bool, Version)
CabalParsing m => m (Bool, Version)
verOrWild
              Bool -> m ()
forall {f :: * -> *}. CabalParsing f => Bool -> f ()
checkWild Bool
wild
              VersionRange -> m VersionRange
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VersionRange -> m VersionRange) -> VersionRange -> m VersionRange
forall a b. (a -> b) -> a -> b
$ (if Bool
wild then Version -> VersionRange
withinVersion else Version -> VersionRange
thisVersion) Version
v
              m VersionRange -> m VersionRange -> m VersionRange
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((Version -> VersionRange) -> NonEmpty Version -> m VersionRange
forall {f :: * -> *} {a}.
MonadFail f =>
(a -> VersionRange) -> NonEmpty a -> f VersionRange
verSet' Version -> VersionRange
thisVersion (NonEmpty Version -> m VersionRange)
-> m (NonEmpty Version) -> m VersionRange
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m (NonEmpty Version)
CabalParsing m => m (NonEmpty Version)
verSet)
            )
        String
"^>=" -> do
          m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
          ( do
              (Bool
wild, Version
v) <- m (Bool, Version)
CabalParsing m => m (Bool, Version)
verOrWild
              Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
wild (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
                String -> m ()
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
P.unexpected (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$
                  String
"wild-card version after ^>= operator"
              Version -> m VersionRange
forall {f :: * -> *}. MonadFail f => Version -> f VersionRange
majorBoundVersion' Version
v
              m VersionRange -> m VersionRange -> m VersionRange
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((Version -> VersionRange) -> NonEmpty Version -> m VersionRange
forall {f :: * -> *} {a}.
MonadFail f =>
(a -> VersionRange) -> NonEmpty a -> f VersionRange
verSet' Version -> VersionRange
majorBoundVersion (NonEmpty Version -> m VersionRange)
-> m (NonEmpty Version) -> m VersionRange
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m (NonEmpty Version)
CabalParsing m => m (NonEmpty Version)
verSet)
            )
        String
_ -> do
          m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
          (Bool
wild, Version
v) <- m (Bool, Version)
CabalParsing m => m (Bool, Version)
verOrWild
          Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
wild (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
            String -> m ()
forall a. String -> m a
forall (m :: * -> *) a. Parsing m => String -> m a
P.unexpected (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$
              String
"wild-card version after non-== operator: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
op
          case String
op of
            String
">=" -> VersionRange -> m VersionRange
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VersionRange -> m VersionRange) -> VersionRange -> m VersionRange
forall a b. (a -> b) -> a -> b
$ Version -> VersionRange
orLaterVersion Version
v
            String
"<" -> VersionRange -> m VersionRange
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VersionRange -> m VersionRange) -> VersionRange -> m VersionRange
forall a b. (a -> b) -> a -> b
$ Version -> VersionRange
earlierVersion Version
v
            String
"<=" -> VersionRange -> m VersionRange
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VersionRange -> m VersionRange) -> VersionRange -> m VersionRange
forall a b. (a -> b) -> a -> b
$ Version -> VersionRange
orEarlierVersion Version
v
            String
">" -> VersionRange -> m VersionRange
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VersionRange -> m VersionRange) -> VersionRange -> m VersionRange
forall a b. (a -> b) -> a -> b
$ Version -> VersionRange
laterVersion Version
v
            String
_ -> String -> m VersionRange
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m VersionRange) -> String -> m VersionRange
forall a b. (a -> b) -> a -> b
$ String
"Unknown version operator " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
op

    -- Cannot be warning
    -- On 2020-03-16 there was around 27400 files on Hackage failing to parse due this
    -- For example https://hackage.haskell.org/package/haxr-3000.0.0/haxr.cabal
    --
    checkOp :: m ()
checkOp =
      Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CabalSpecVersion
csv CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
< CabalSpecVersion
CabalSpecV1_8) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
        PWarnType -> String -> m ()
forall (m :: * -> *). CabalParsing m => PWarnType -> String -> m ()
parsecWarning PWarnType
PWTVersionOperator (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$
          [String] -> String
unwords
            [ String
"version operators used."
            , String
"To use version operators the package needs to specify at least 'cabal-version: >= 1.8'."
            ]

    -- Cannot be warning
    -- On 2020-03-16 there was 46 files on Hackage failing to parse due this
    -- For example https://hackage.haskell.org/package/derive-0.1.2/derive.cabal
    --
    checkWild :: Bool -> f ()
checkWild Bool
False = () -> f ()
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
    checkWild Bool
True =
      Bool -> f () -> f ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CabalSpecVersion
csv CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
< CabalSpecVersion
CabalSpecV1_6) (f () -> f ()) -> f () -> f ()
forall a b. (a -> b) -> a -> b
$
        PWarnType -> String -> f ()
forall (m :: * -> *). CabalParsing m => PWarnType -> String -> m ()
parsecWarning PWarnType
PWTVersionWildcard (String -> f ()) -> String -> f ()
forall a b. (a -> b) -> a -> b
$
          [String] -> String
unwords
            [ String
"Wildcard syntax used."
            , String
"To use version wildcards the package needs to specify at least 'cabal-version: >= 1.6'."
            ]

    -- https://gitlab.haskell.org/ghc/ghc/issues/17752
    isOpChar :: Char -> Bool
isOpChar Char
'<' = Bool
True
    isOpChar Char
'=' = Bool
True
    isOpChar Char
'>' = Bool
True
    isOpChar Char
'^' = Bool
True
    isOpChar Char
'-' = CabalSpecVersion
csv CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
< CabalSpecVersion
CabalSpecV3_4
    -- https://github.com/haskell/cabal/issues/6589
    -- Unfortunately we have must not consume the dash,
    -- as otherwise following parts may not be parsed.
    --
    -- i.e. we cannot fail here with good error.
    isOpChar Char
_ = Bool
False

    -- -none version range is available since 1.22
    noVersion' :: m VersionRange
noVersion' =
      if CabalSpecVersion
csv CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
>= CabalSpecVersion
CabalSpecV1_22
        then VersionRange -> m VersionRange
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure VersionRange
noVersion
        else
          String -> m VersionRange
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m VersionRange) -> String -> m VersionRange
forall a b. (a -> b) -> a -> b
$
            [String] -> String
unwords
              [ String
"-none version range used."
              , String
"To use this syntax the package needs to specify at least 'cabal-version: 1.22'."
              , String
"Alternatively, if broader compatibility is important then use"
              , String
"<0 or other empty range."
              ]

    -- \^>= is available since 2.0
    majorBoundVersion' :: Version -> f VersionRange
majorBoundVersion' Version
v =
      if CabalSpecVersion
csv CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
>= CabalSpecVersion
CabalSpecV2_0
        then VersionRange -> f VersionRange
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VersionRange -> f VersionRange) -> VersionRange -> f VersionRange
forall a b. (a -> b) -> a -> b
$ Version -> VersionRange
majorBoundVersion Version
v
        else
          String -> f VersionRange
forall a. String -> f a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> f VersionRange) -> String -> f VersionRange
forall a b. (a -> b) -> a -> b
$
            [String] -> String
unwords
              [ String
"major bounded version syntax (caret, ^>=) used."
              , String
"To use this syntax the package need to specify at least 'cabal-version: 2.0'."
              , String
"Alternatively, if broader compatibility is important then use:"
              , VersionRange -> String
forall a. Pretty a => a -> String
prettyShow (VersionRange -> String) -> VersionRange -> String
forall a b. (a -> b) -> a -> b
$ VersionRange -> VersionRange
eliminateMajorBoundSyntax (VersionRange -> VersionRange) -> VersionRange -> VersionRange
forall a b. (a -> b) -> a -> b
$ Version -> VersionRange
majorBoundVersion Version
v
              ]
      where
        eliminateMajorBoundSyntax :: VersionRange -> VersionRange
eliminateMajorBoundSyntax = (VersionRangeF VersionRange -> VersionRange)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRange
hyloVersionRange VersionRangeF VersionRange -> VersionRange
embed VersionRange -> VersionRangeF VersionRange
projectVersionRange
        embed :: VersionRangeF VersionRange -> VersionRange
embed (MajorBoundVersionF Version
u) =
          VersionRange -> VersionRange -> VersionRange
intersectVersionRanges
            (Version -> VersionRange
orLaterVersion Version
u)
            (Version -> VersionRange
earlierVersion (Version -> Version
majorUpperBound Version
u))
        embed VersionRangeF VersionRange
vr = VersionRangeF VersionRange -> VersionRange
embedVersionRange VersionRangeF VersionRange
vr

    -- version set notation (e.g. "== { 0.0.1.0, 0.0.2.0, 0.1.0.0 }")
    verSet' :: (a -> VersionRange) -> NonEmpty a -> f VersionRange
verSet' a -> VersionRange
op NonEmpty a
vs =
      if CabalSpecVersion
csv CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
>= CabalSpecVersion
CabalSpecV3_0
        then VersionRange -> f VersionRange
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VersionRange -> f VersionRange) -> VersionRange -> f VersionRange
forall a b. (a -> b) -> a -> b
$ (VersionRange -> VersionRange -> VersionRange)
-> NonEmpty VersionRange -> VersionRange
forall a. (a -> a -> a) -> NonEmpty a -> a
foldr1 VersionRange -> VersionRange -> VersionRange
unionVersionRanges ((a -> VersionRange) -> NonEmpty a -> NonEmpty VersionRange
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> VersionRange
op NonEmpty a
vs)
        else
          String -> f VersionRange
forall a. String -> f a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> f VersionRange) -> String -> f VersionRange
forall a b. (a -> b) -> a -> b
$
            [String] -> String
unwords
              [ String
"version set syntax used."
              , String
"To use this syntax the package needs to specify at least 'cabal-version: 3.0'."
              , String
"Alternatively, if broader compatibility is important then use"
              , String
"a series of single version constraints joined with the || operator:"
              , VersionRange -> String
forall a. Pretty a => a -> String
prettyShow ((VersionRange -> VersionRange -> VersionRange)
-> NonEmpty VersionRange -> VersionRange
forall a. (a -> a -> a) -> NonEmpty a -> a
foldr1 VersionRange -> VersionRange -> VersionRange
unionVersionRanges ((a -> VersionRange) -> NonEmpty a -> NonEmpty VersionRange
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> VersionRange
op NonEmpty a
vs))
              ]

    verSet :: CabalParsing m => m (NonEmpty Version)
    verSet :: CabalParsing m => m (NonEmpty Version)
verSet = do
      Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'{'
      m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
      NonEmpty Version
vs <- m Version -> m () -> m (NonEmpty Version)
forall (m :: * -> *) a sep.
Alternative m =>
m a -> m sep -> m (NonEmpty a)
P.sepByNonEmpty (m Version
CabalParsing m => m Version
verPlain m Version -> m () -> m Version
forall a b. m a -> m b -> m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces) (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
',' m Char -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces)
      Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'}'
      NonEmpty Version -> m (NonEmpty Version)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NonEmpty Version
vs

    -- a plain version without tags or wildcards
    verPlain :: CabalParsing m => m Version
    verPlain :: CabalParsing m => m Version
verPlain = [Int] -> Version
mkVersion ([Int] -> Version)
-> (NonEmpty Int -> [Int]) -> NonEmpty Int -> Version
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty Int -> [Int]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (NonEmpty Int -> Version) -> m (NonEmpty Int) -> m Version
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int -> m Char -> m (NonEmpty Int)
forall (m :: * -> *) a sep.
Alternative m =>
m a -> m sep -> m (NonEmpty a)
P.sepByNonEmpty m Int
digitParser (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'.')

    -- either wildcard or normal version
    verOrWild :: CabalParsing m => m (Bool, Version)
    verOrWild :: CabalParsing m => m (Bool, Version)
verOrWild = do
      Int
x <- m Int
digitParser
      DList Int -> m (Bool, Version)
CabalParsing m => DList Int -> m (Bool, Version)
verLoop (Int -> DList Int
forall a. a -> DList a
DList.singleton Int
x)

    -- trailing: wildcard (.y.*) or normal version (optional tags) (.y.z-tag)
    verLoop :: CabalParsing m => DList.DList Int -> m (Bool, Version)
    verLoop :: CabalParsing m => DList Int -> m (Bool, Version)
verLoop DList Int
acc =
      DList Int -> m (Bool, Version)
CabalParsing m => DList Int -> m (Bool, Version)
verLoop' DList Int
acc
        m (Bool, Version) -> m (Bool, Version) -> m (Bool, Version)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (m ()
CabalParsing m => m ()
tags m () -> m (Bool, Version) -> m (Bool, Version)
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Bool, Version) -> m (Bool, Version)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool
False, [Int] -> Version
mkVersion (DList Int -> [Int]
forall a. DList a -> [a]
DList.toList DList Int
acc)))

    verLoop' :: CabalParsing m => DList.DList Int -> m (Bool, Version)
    verLoop' :: CabalParsing m => DList Int -> m (Bool, Version)
verLoop' DList Int
acc = do
      Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'.'
      let digit :: m (Bool, Version)
digit = m Int
digitParser m Int -> (Int -> m (Bool, Version)) -> m (Bool, Version)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= DList Int -> m (Bool, Version)
CabalParsing m => DList Int -> m (Bool, Version)
verLoop (DList Int -> m (Bool, Version))
-> (Int -> DList Int) -> Int -> m (Bool, Version)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList Int -> Int -> DList Int
forall a. DList a -> a -> DList a
DList.snoc DList Int
acc
      let wild :: m (Bool, Version)
wild = (Bool
True, [Int] -> Version
mkVersion (DList Int -> [Int]
forall a. DList a -> [a]
DList.toList DList Int
acc)) (Bool, Version) -> m Char -> m (Bool, Version)
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'*'
      m (Bool, Version)
digit m (Bool, Version) -> m (Bool, Version) -> m (Bool, Version)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (Bool, Version)
wild

    parens :: m a -> m a
parens m a
p = m () -> m () -> m a -> m a
forall (m :: * -> *) bra ket a.
Applicative m =>
m bra -> m ket -> m a -> m a
P.between
      ((Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'(' m Char -> String -> m Char
forall a. m a -> String -> m a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
P.<?> String
"opening paren") m Char -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces)
      (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
')' m Char -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces)
      (m a -> m a) -> m a -> m a
forall a b. (a -> b) -> a -> b
$ do
        a
a <- m a
p
        m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
        a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

    tags :: CabalParsing m => m ()
    tags :: CabalParsing m => m ()
tags = do
      [String]
ts <- m String -> m [String]
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (m String -> m [String]) -> m String -> m [String]
forall a b. (a -> b) -> a -> b
$ Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'-' m Char -> m String -> m String
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m Char -> m String
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some ((Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
P.satisfy Char -> Bool
isAlphaNum)
      case [String]
ts of
        [] -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
        (String
_ : [String]
_) -> PWarnType -> String -> m ()
forall (m :: * -> *). CabalParsing m => PWarnType -> String -> m ()
parsecWarning PWarnType
PWTVersionTag String
"version with tags"

----------------------------
-- Wildcard range utilities
--

-- | Compute next greater major version to be used as upper bound.
--
-- Example: @0.4.1@ produces the version @0.5@ which then can be used
-- to construct a range @>= 0.4.1 && < 0.5@
--
-- @since 2.2
majorUpperBound :: Version -> Version
majorUpperBound :: Version -> Version
majorUpperBound = ([Int] -> [Int]) -> Version -> Version
alterVersion (([Int] -> [Int]) -> Version -> Version)
-> ([Int] -> [Int]) -> Version -> Version
forall a b. (a -> b) -> a -> b
$ \[Int]
numbers -> case [Int]
numbers of
  [] -> [Int
0, Int
1] -- should not happen
  [Int
m1] -> [Int
m1, Int
1] -- e.g. version '1'
  (Int
m1 : Int
m2 : [Int]
_) -> [Int
m1, Int
m2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1]

-- | Increment the last version number.
--
-- Example: For @1.2@ this returns @1.3@
-- so that it can be used as upper bound when resolving @== 1.2.*@.
-- For @0.4.1@ it returns @0.4.2@.
--
-- @since 2.2
wildcardUpperBound :: Version -> Version
wildcardUpperBound :: Version -> Version
wildcardUpperBound = ([Int] -> [Int]) -> Version -> Version
alterVersion (([Int] -> [Int]) -> Version -> Version)
-> ([Int] -> [Int]) -> Version -> Version
forall a b. (a -> b) -> a -> b
$
  \[Int]
lowerBound -> case [Int] -> Maybe ([Int], Int)
forall a. [a] -> Maybe ([a], a)
unsnoc [Int]
lowerBound of
    Maybe ([Int], Int)
Nothing -> []
    Just ([Int]
xs, Int
x) -> [Int]
xs [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ [Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1]