{-# 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
(ModuleReexport -> ModuleReexport -> Bool)
-> (ModuleReexport -> ModuleReexport -> Bool) -> Eq ModuleReexport
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, (forall x. ModuleReexport -> Rep ModuleReexport x)
-> (forall x. Rep ModuleReexport x -> ModuleReexport)
-> Generic ModuleReexport
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]
(Int -> ReadS ModuleReexport)
-> ReadS [ModuleReexport]
-> ReadPrec ModuleReexport
-> ReadPrec [ModuleReexport]
-> Read 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
(Int -> ModuleReexport -> ShowS)
-> (ModuleReexport -> String)
-> ([ModuleReexport] -> ShowS)
-> Show ModuleReexport
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
Typeable ModuleReexport
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ModuleReexport -> c ModuleReexport)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ModuleReexport)
-> (ModuleReexport -> Constr)
-> (ModuleReexport -> DataType)
-> (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))
-> ((forall b. Data b => b -> b)
    -> ModuleReexport -> ModuleReexport)
-> (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 u.
    (forall d. Data d => d -> u) -> ModuleReexport -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ModuleReexport -> u)
-> (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 (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ModuleReexport -> m ModuleReexport)
-> Data 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 = ModuleReexport -> ()
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) =
          Doc -> (PackageName -> Doc) -> Maybe PackageName -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
Disp.empty (\PackageName
pkgname -> PackageName -> Doc
forall a. Pretty a => a -> Doc
pretty PackageName
pkgname Doc -> Doc -> Doc
<<>> Char -> Doc
Disp.char Char
':') Maybe PackageName
mpkgname
       Doc -> Doc -> Doc
<<>> ModuleName -> Doc
forall a. Pretty a => a -> Doc
pretty ModuleName
origname
      Doc -> Doc -> Doc
<+> if ModuleName
newname ModuleName -> ModuleName -> Bool
forall a. Eq a => a -> a -> Bool
== ModuleName
origname
            then Doc
Disp.empty
            else String -> Doc
Disp.text String
"as" Doc -> Doc -> Doc
<+> ModuleName -> 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 <- m PackageName -> m (Maybe PackageName)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (m PackageName -> m PackageName
forall (m :: * -> *) a. Parsing m => m a -> m a
P.try (m PackageName -> m PackageName) -> m PackageName -> m PackageName
forall a b. (a -> b) -> a -> b
$ m PackageName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
parsec m PackageName -> m Char -> m PackageName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
':')
        ModuleName
origname <- m ModuleName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
parsec
        ModuleName
newname  <- ModuleName -> m ModuleName -> m ModuleName
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
P.option ModuleName
origname (m ModuleName -> m ModuleName) -> m ModuleName -> m ModuleName
forall a b. (a -> b) -> a -> b
$ m ModuleName -> m ModuleName
forall (m :: * -> *) a. Parsing m => m a -> m a
P.try (m ModuleName -> m ModuleName) -> m ModuleName -> m ModuleName
forall a b. (a -> b) -> a -> b
$ do
            m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
            String
_ <- String -> m String
forall (m :: * -> *). CharParsing m => String -> m String
P.string String
"as"
            m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
            m ModuleName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
parsec
        ModuleReexport -> m ModuleReexport
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PackageName -> ModuleName -> ModuleName -> ModuleReexport
ModuleReexport Maybe PackageName
mpkgname ModuleName
origname ModuleName
newname)