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