{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.PackageName
  ( PackageName
  , unPackageName, mkPackageName
  , unPackageNameST, mkPackageNameST
  ) where

import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Utils.ShortText

import qualified Text.PrettyPrint as Disp
import Distribution.Pretty
import Distribution.Parsec

-- | A package name.
--
-- Use 'mkPackageName' and 'unPackageName' to convert from/to a
-- 'String'.
--
-- This type is opaque since @Cabal-2.0@
--
-- @since 2.0.0.2
newtype PackageName = PackageName ShortText
    deriving ((forall x. PackageName -> Rep PackageName x)
-> (forall x. Rep PackageName x -> PackageName)
-> Generic PackageName
forall x. Rep PackageName x -> PackageName
forall x. PackageName -> Rep PackageName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PackageName -> Rep PackageName x
from :: forall x. PackageName -> Rep PackageName x
$cto :: forall x. Rep PackageName x -> PackageName
to :: forall x. Rep PackageName x -> PackageName
Generic, ReadPrec [PackageName]
ReadPrec PackageName
Int -> ReadS PackageName
ReadS [PackageName]
(Int -> ReadS PackageName)
-> ReadS [PackageName]
-> ReadPrec PackageName
-> ReadPrec [PackageName]
-> Read PackageName
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PackageName
readsPrec :: Int -> ReadS PackageName
$creadList :: ReadS [PackageName]
readList :: ReadS [PackageName]
$creadPrec :: ReadPrec PackageName
readPrec :: ReadPrec PackageName
$creadListPrec :: ReadPrec [PackageName]
readListPrec :: ReadPrec [PackageName]
Read, Int -> PackageName -> ShowS
[PackageName] -> ShowS
PackageName -> String
(Int -> PackageName -> ShowS)
-> (PackageName -> String)
-> ([PackageName] -> ShowS)
-> Show PackageName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PackageName -> ShowS
showsPrec :: Int -> PackageName -> ShowS
$cshow :: PackageName -> String
show :: PackageName -> String
$cshowList :: [PackageName] -> ShowS
showList :: [PackageName] -> ShowS
Show, PackageName -> PackageName -> Bool
(PackageName -> PackageName -> Bool)
-> (PackageName -> PackageName -> Bool) -> Eq PackageName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PackageName -> PackageName -> Bool
== :: PackageName -> PackageName -> Bool
$c/= :: PackageName -> PackageName -> Bool
/= :: PackageName -> PackageName -> Bool
Eq, Eq PackageName
Eq PackageName =>
(PackageName -> PackageName -> Ordering)
-> (PackageName -> PackageName -> Bool)
-> (PackageName -> PackageName -> Bool)
-> (PackageName -> PackageName -> Bool)
-> (PackageName -> PackageName -> Bool)
-> (PackageName -> PackageName -> PackageName)
-> (PackageName -> PackageName -> PackageName)
-> Ord PackageName
PackageName -> PackageName -> Bool
PackageName -> PackageName -> Ordering
PackageName -> PackageName -> PackageName
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 :: PackageName -> PackageName -> Ordering
compare :: PackageName -> PackageName -> Ordering
$c< :: PackageName -> PackageName -> Bool
< :: PackageName -> PackageName -> Bool
$c<= :: PackageName -> PackageName -> Bool
<= :: PackageName -> PackageName -> Bool
$c> :: PackageName -> PackageName -> Bool
> :: PackageName -> PackageName -> Bool
$c>= :: PackageName -> PackageName -> Bool
>= :: PackageName -> PackageName -> Bool
$cmax :: PackageName -> PackageName -> PackageName
max :: PackageName -> PackageName -> PackageName
$cmin :: PackageName -> PackageName -> PackageName
min :: PackageName -> PackageName -> PackageName
Ord, Typeable, Typeable PackageName
Typeable PackageName =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PackageName -> c PackageName)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PackageName)
-> (PackageName -> Constr)
-> (PackageName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PackageName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c PackageName))
-> ((forall b. Data b => b -> b) -> PackageName -> PackageName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PackageName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PackageName -> r)
-> (forall u. (forall d. Data d => d -> u) -> PackageName -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PackageName -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PackageName -> m PackageName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PackageName -> m PackageName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PackageName -> m PackageName)
-> Data PackageName
PackageName -> Constr
PackageName -> DataType
(forall b. Data b => b -> b) -> PackageName -> PackageName
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) -> PackageName -> u
forall u. (forall d. Data d => d -> u) -> PackageName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PackageName -> m PackageName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageName -> m PackageName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PackageName -> c PackageName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageName)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PackageName -> c PackageName
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PackageName -> c PackageName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageName
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageName
$ctoConstr :: PackageName -> Constr
toConstr :: PackageName -> Constr
$cdataTypeOf :: PackageName -> DataType
dataTypeOf :: PackageName -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageName)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageName)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageName)
$cgmapT :: (forall b. Data b => b -> b) -> PackageName -> PackageName
gmapT :: (forall b. Data b => b -> b) -> PackageName -> PackageName
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageName -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageName -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageName -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PackageName -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PackageName -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PackageName -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PackageName -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PackageName -> m PackageName
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PackageName -> m PackageName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageName -> m PackageName
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageName -> m PackageName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageName -> m PackageName
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageName -> m PackageName
Data)

-- | Convert 'PackageName' to 'String'
unPackageName :: PackageName -> String
unPackageName :: PackageName -> String
unPackageName (PackageName ShortText
s) = ShortText -> String
fromShortText ShortText
s

-- | @since 3.4.0.0
unPackageNameST :: PackageName -> ShortText
unPackageNameST :: PackageName -> ShortText
unPackageNameST (PackageName ShortText
s) = ShortText
s

-- | Construct a 'PackageName' from a 'String'
--
-- 'mkPackageName' is the inverse to 'unPackageName'
--
-- Note: No validations are performed to ensure that the resulting
-- 'PackageName' is valid
--
-- @since 2.0.0.2
mkPackageName :: String -> PackageName
mkPackageName :: String -> PackageName
mkPackageName = ShortText -> PackageName
PackageName (ShortText -> PackageName)
-> (String -> ShortText) -> String -> PackageName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShortText
toShortText

-- | Construct a 'PackageName' from a 'ShortText'
--
-- Note: No validations are performed to ensure that the resulting
-- 'PackageName' is valid
--
-- @since 3.4.0.0
mkPackageNameST :: ShortText -> PackageName
mkPackageNameST :: ShortText -> PackageName
mkPackageNameST = ShortText -> PackageName
PackageName

-- | 'mkPackageName'
--
-- @since 2.0.0.2
instance IsString PackageName where
  fromString :: String -> PackageName
fromString = String -> PackageName
mkPackageName

instance Binary PackageName
instance Structured PackageName

instance Pretty PackageName where
  pretty :: PackageName -> Doc
pretty = String -> Doc
Disp.text (String -> Doc) -> (PackageName -> String) -> PackageName -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageName -> String
unPackageName

instance Parsec PackageName where
  parsec :: forall (m :: * -> *). CabalParsing m => m PackageName
parsec = String -> PackageName
mkPackageName (String -> PackageName) -> m String -> m PackageName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String
forall (m :: * -> *). CabalParsing m => m String
parsecUnqualComponentName

instance NFData PackageName where
    rnf :: PackageName -> ()
rnf (PackageName ShortText
pkg) = ShortText -> ()
forall a. NFData a => a -> ()
rnf ShortText
pkg