{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}

module Distribution.Types.ModuleReexport (
    ModuleReexport(..)
) where

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.ModuleName
import Distribution.Parsec
import Distribution.Pretty
import Distribution.Types.PackageName

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

-- -----------------------------------------------------------------------------
-- Module re-exports

data ModuleReexport = ModuleReexport {
       ModuleReexport -> Maybe PackageName
moduleReexportOriginalPackage :: Maybe PackageName,
       ModuleReexport -> ModuleName
moduleReexportOriginalName    :: ModuleName,
       ModuleReexport -> ModuleName
moduleReexportName            :: ModuleName
    }
    deriving (ModuleReexport -> ModuleReexport -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ModuleReexport -> ModuleReexport -> Bool
$c/= :: ModuleReexport -> ModuleReexport -> Bool
== :: ModuleReexport -> ModuleReexport -> Bool
$c== :: ModuleReexport -> ModuleReexport -> Bool
Eq, Eq ModuleReexport
ModuleReexport -> ModuleReexport -> Bool
ModuleReexport -> ModuleReexport -> Ordering
ModuleReexport -> ModuleReexport -> ModuleReexport
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
min :: ModuleReexport -> ModuleReexport -> ModuleReexport
$cmin :: ModuleReexport -> ModuleReexport -> ModuleReexport
max :: ModuleReexport -> ModuleReexport -> ModuleReexport
$cmax :: ModuleReexport -> ModuleReexport -> ModuleReexport
>= :: ModuleReexport -> ModuleReexport -> Bool
$c>= :: ModuleReexport -> ModuleReexport -> Bool
> :: ModuleReexport -> ModuleReexport -> Bool
$c> :: ModuleReexport -> ModuleReexport -> Bool
<= :: ModuleReexport -> ModuleReexport -> Bool
$c<= :: ModuleReexport -> ModuleReexport -> Bool
< :: ModuleReexport -> ModuleReexport -> Bool
$c< :: ModuleReexport -> ModuleReexport -> Bool
compare :: ModuleReexport -> ModuleReexport -> Ordering
$ccompare :: ModuleReexport -> ModuleReexport -> Ordering
Ord, forall x. Rep ModuleReexport x -> ModuleReexport
forall x. ModuleReexport -> Rep ModuleReexport x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ModuleReexport x -> ModuleReexport
$cfrom :: forall x. ModuleReexport -> Rep ModuleReexport x
Generic, ReadPrec [ModuleReexport]
ReadPrec ModuleReexport
Int -> ReadS ModuleReexport
ReadS [ModuleReexport]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ModuleReexport]
$creadListPrec :: ReadPrec [ModuleReexport]
readPrec :: ReadPrec ModuleReexport
$creadPrec :: ReadPrec ModuleReexport
readList :: ReadS [ModuleReexport]
$creadList :: ReadS [ModuleReexport]
readsPrec :: Int -> ReadS ModuleReexport
$creadsPrec :: Int -> ReadS ModuleReexport
Read, Int -> ModuleReexport -> ShowS
[ModuleReexport] -> ShowS
ModuleReexport -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ModuleReexport] -> ShowS
$cshowList :: [ModuleReexport] -> ShowS
show :: ModuleReexport -> String
$cshow :: ModuleReexport -> String
showsPrec :: Int -> ModuleReexport -> ShowS
$cshowsPrec :: Int -> ModuleReexport -> ShowS
Show, Typeable, Typeable ModuleReexport
ModuleReexport -> DataType
ModuleReexport -> Constr
(forall b. Data b => b -> b) -> ModuleReexport -> ModuleReexport
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) -> ModuleReexport -> u
forall u. (forall d. Data d => d -> u) -> ModuleReexport -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleReexport -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleReexport -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ModuleReexport -> m ModuleReexport
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ModuleReexport -> m ModuleReexport
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModuleReexport
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModuleReexport -> c ModuleReexport
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ModuleReexport)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ModuleReexport)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ModuleReexport -> m ModuleReexport
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ModuleReexport -> m ModuleReexport
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ModuleReexport -> m ModuleReexport
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ModuleReexport -> m ModuleReexport
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ModuleReexport -> m ModuleReexport
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ModuleReexport -> m ModuleReexport
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> ModuleReexport -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> ModuleReexport -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ModuleReexport -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ModuleReexport -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleReexport -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleReexport -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleReexport -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ModuleReexport -> r
gmapT :: (forall b. Data b => b -> b) -> ModuleReexport -> ModuleReexport
$cgmapT :: (forall b. Data b => b -> b) -> ModuleReexport -> ModuleReexport
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ModuleReexport)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ModuleReexport)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ModuleReexport)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ModuleReexport)
dataTypeOf :: ModuleReexport -> DataType
$cdataTypeOf :: ModuleReexport -> DataType
toConstr :: ModuleReexport -> Constr
$ctoConstr :: ModuleReexport -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModuleReexport
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ModuleReexport
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModuleReexport -> c ModuleReexport
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ModuleReexport -> c ModuleReexport
Data)

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

instance Pretty ModuleReexport where
    pretty :: ModuleReexport -> Doc
pretty (ModuleReexport Maybe PackageName
mpkgname ModuleName
origname ModuleName
newname) =
          forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
Disp.empty (\PackageName
pkgname -> forall a. Pretty a => a -> Doc
pretty PackageName
pkgname Doc -> Doc -> Doc
<<>> Char -> Doc
Disp.char Char
':') Maybe PackageName
mpkgname
       Doc -> Doc -> Doc
<<>> forall a. Pretty a => a -> Doc
pretty ModuleName
origname
      Doc -> Doc -> Doc
<+> if ModuleName
newname forall a. Eq a => a -> a -> Bool
== ModuleName
origname
            then Doc
Disp.empty
            else String -> Doc
Disp.text String
"as" Doc -> Doc -> Doc
<+> forall a. Pretty a => a -> Doc
pretty ModuleName
newname

instance Parsec ModuleReexport where
    parsec :: forall (m :: * -> *). CabalParsing m => m ModuleReexport
parsec = do
        Maybe PackageName
mpkgname <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (forall (m :: * -> *) a. Parsing m => m a -> m a
P.try forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
parsec forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
':')
        ModuleName
origname <- forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
parsec
        ModuleName
newname  <- forall (m :: * -> *) a. Alternative m => a -> m a -> m a
P.option ModuleName
origname forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Parsing m => m a -> m a
P.try forall a b. (a -> b) -> a -> b
$ do
            forall (m :: * -> *). CharParsing m => m ()
P.spaces
            String
_ <- forall (m :: * -> *). CharParsing m => String -> m String
P.string String
"as"
            forall (m :: * -> *). CharParsing m => m ()
P.spaces
            forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
parsec
        forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PackageName -> ModuleName -> ModuleName -> ModuleReexport
ModuleReexport Maybe PackageName
mpkgname ModuleName
origname ModuleName
newname)