module Distribution.Types.IncludeRenaming (
IncludeRenaming(..),
defaultIncludeRenaming,
isDefaultIncludeRenaming,
) where
import Distribution.Compat.Prelude
import Prelude ()
import Distribution.Types.ModuleRenaming
import qualified Distribution.Compat.CharParsing as P
import Distribution.Parsec
import Distribution.Pretty
import Text.PrettyPrint (text, (<+>))
import qualified Text.PrettyPrint as Disp
data IncludeRenaming
= IncludeRenaming {
includeProvidesRn :: ModuleRenaming,
includeRequiresRn :: ModuleRenaming
}
deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
instance Binary IncludeRenaming
instance Structured IncludeRenaming
instance NFData IncludeRenaming where rnf = genericRnf
defaultIncludeRenaming :: IncludeRenaming
defaultIncludeRenaming = IncludeRenaming defaultRenaming defaultRenaming
isDefaultIncludeRenaming :: IncludeRenaming -> Bool
isDefaultIncludeRenaming (IncludeRenaming p r) = isDefaultRenaming p && isDefaultRenaming r
instance Pretty IncludeRenaming where
pretty (IncludeRenaming prov_rn req_rn) =
pretty prov_rn
<+> (if isDefaultRenaming req_rn
then Disp.empty
else text "requires" <+> pretty req_rn)
instance Parsec IncludeRenaming where
parsec = do
prov_rn <- parsec
req_rn <- P.option defaultRenaming $ P.try $ do
P.spaces
_ <- P.string "requires"
P.spaces
parsec
return (IncludeRenaming prov_rn req_rn)