{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} module Distribution.Types.LibraryName ( LibraryName(..), defaultLibName, maybeToLibraryName, showLibraryName, libraryNameStanza, libraryNameString, -- * Pretty & Parse prettyLibraryNameComponent, parsecLibraryNameComponent, ) where import Prelude () import Distribution.Compat.Prelude import Distribution.Types.UnqualComponentName import Distribution.Pretty import Distribution.Parsec import qualified Distribution.Compat.CharParsing as P import qualified Text.PrettyPrint as Disp data LibraryName = LMainLibName | LSubLibName UnqualComponentName deriving (LibraryName -> LibraryName -> Bool (LibraryName -> LibraryName -> Bool) -> (LibraryName -> LibraryName -> Bool) -> Eq LibraryName forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: LibraryName -> LibraryName -> Bool $c/= :: LibraryName -> LibraryName -> Bool == :: LibraryName -> LibraryName -> Bool $c== :: LibraryName -> LibraryName -> Bool Eq, (forall x. LibraryName -> Rep LibraryName x) -> (forall x. Rep LibraryName x -> LibraryName) -> Generic LibraryName forall x. Rep LibraryName x -> LibraryName forall x. LibraryName -> Rep LibraryName x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep LibraryName x -> LibraryName $cfrom :: forall x. LibraryName -> Rep LibraryName x Generic, Eq LibraryName Eq LibraryName -> (LibraryName -> LibraryName -> Ordering) -> (LibraryName -> LibraryName -> Bool) -> (LibraryName -> LibraryName -> Bool) -> (LibraryName -> LibraryName -> Bool) -> (LibraryName -> LibraryName -> Bool) -> (LibraryName -> LibraryName -> LibraryName) -> (LibraryName -> LibraryName -> LibraryName) -> Ord LibraryName LibraryName -> LibraryName -> Bool LibraryName -> LibraryName -> Ordering LibraryName -> LibraryName -> LibraryName 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 :: LibraryName -> LibraryName -> LibraryName $cmin :: LibraryName -> LibraryName -> LibraryName max :: LibraryName -> LibraryName -> LibraryName $cmax :: LibraryName -> LibraryName -> LibraryName >= :: LibraryName -> LibraryName -> Bool $c>= :: LibraryName -> LibraryName -> Bool > :: LibraryName -> LibraryName -> Bool $c> :: LibraryName -> LibraryName -> Bool <= :: LibraryName -> LibraryName -> Bool $c<= :: LibraryName -> LibraryName -> Bool < :: LibraryName -> LibraryName -> Bool $c< :: LibraryName -> LibraryName -> Bool compare :: LibraryName -> LibraryName -> Ordering $ccompare :: LibraryName -> LibraryName -> Ordering Ord, ReadPrec [LibraryName] ReadPrec LibraryName Int -> ReadS LibraryName ReadS [LibraryName] (Int -> ReadS LibraryName) -> ReadS [LibraryName] -> ReadPrec LibraryName -> ReadPrec [LibraryName] -> Read LibraryName forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [LibraryName] $creadListPrec :: ReadPrec [LibraryName] readPrec :: ReadPrec LibraryName $creadPrec :: ReadPrec LibraryName readList :: ReadS [LibraryName] $creadList :: ReadS [LibraryName] readsPrec :: Int -> ReadS LibraryName $creadsPrec :: Int -> ReadS LibraryName Read, Int -> LibraryName -> ShowS [LibraryName] -> ShowS LibraryName -> String (Int -> LibraryName -> ShowS) -> (LibraryName -> String) -> ([LibraryName] -> ShowS) -> Show LibraryName forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [LibraryName] -> ShowS $cshowList :: [LibraryName] -> ShowS show :: LibraryName -> String $cshow :: LibraryName -> String showsPrec :: Int -> LibraryName -> ShowS $cshowsPrec :: Int -> LibraryName -> ShowS Show, Typeable, Typeable LibraryName Typeable LibraryName -> (forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LibraryName -> c LibraryName) -> (forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LibraryName) -> (LibraryName -> Constr) -> (LibraryName -> DataType) -> (forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LibraryName)) -> (forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibraryName)) -> ((forall b. Data b => b -> b) -> LibraryName -> LibraryName) -> (forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r) -> (forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r) -> (forall u. (forall d. Data d => d -> u) -> LibraryName -> [u]) -> (forall u. Int -> (forall d. Data d => d -> u) -> LibraryName -> u) -> (forall (m :: * -> *). Monad m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName) -> (forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName) -> (forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName) -> Data LibraryName LibraryName -> DataType LibraryName -> Constr (forall b. Data b => b -> b) -> LibraryName -> LibraryName 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) -> LibraryName -> u forall u. (forall d. Data d => d -> u) -> LibraryName -> [u] forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r forall (m :: * -> *). Monad m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LibraryName forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LibraryName -> c LibraryName forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LibraryName) forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibraryName) gmapMo :: forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName $cgmapMo :: forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName gmapMp :: forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName $cgmapMp :: forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName gmapM :: forall (m :: * -> *). Monad m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName $cgmapM :: forall (m :: * -> *). Monad m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LibraryName -> u $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LibraryName -> u gmapQ :: forall u. (forall d. Data d => d -> u) -> LibraryName -> [u] $cgmapQ :: forall u. (forall d. Data d => d -> u) -> LibraryName -> [u] gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r $cgmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r gmapQl :: forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r $cgmapQl :: forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r gmapT :: (forall b. Data b => b -> b) -> LibraryName -> LibraryName $cgmapT :: (forall b. Data b => b -> b) -> LibraryName -> LibraryName dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibraryName) $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibraryName) dataCast1 :: forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LibraryName) $cdataCast1 :: forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LibraryName) dataTypeOf :: LibraryName -> DataType $cdataTypeOf :: LibraryName -> DataType toConstr :: LibraryName -> Constr $ctoConstr :: LibraryName -> Constr gunfold :: forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LibraryName $cgunfold :: forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LibraryName gfoldl :: forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LibraryName -> c LibraryName $cgfoldl :: forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LibraryName -> c LibraryName Data) instance Binary LibraryName instance Structured LibraryName instance NFData LibraryName where rnf :: LibraryName -> () rnf = LibraryName -> () forall a. (Generic a, GNFData (Rep a)) => a -> () genericRnf -- | Pretty print 'LibraryName' in build-target-ish syntax. -- -- /Note:/ there are no 'Pretty' or 'Parsec' instances, -- as there's other way to represent 'LibraryName', namely as bare -- 'UnqualComponentName'. prettyLibraryNameComponent :: LibraryName -> Disp.Doc prettyLibraryNameComponent :: LibraryName -> Doc prettyLibraryNameComponent LibraryName LMainLibName = String -> Doc Disp.text String "lib" prettyLibraryNameComponent (LSubLibName UnqualComponentName str) = String -> Doc Disp.text String "lib:" Doc -> Doc -> Doc <<>> UnqualComponentName -> Doc forall a. Pretty a => a -> Doc pretty UnqualComponentName str parsecLibraryNameComponent :: CabalParsing m => m LibraryName parsecLibraryNameComponent :: forall (m :: * -> *). CabalParsing m => m LibraryName parsecLibraryNameComponent = do String _ <- String -> m String forall (m :: * -> *). CharParsing m => String -> m String P.string String "lib" m LibraryName parseComposite m LibraryName -> m LibraryName -> m LibraryName forall (f :: * -> *) a. Alternative f => f a -> f a -> f a <|> m LibraryName parseSingle where parseSingle :: m LibraryName parseSingle = LibraryName -> m LibraryName forall (m :: * -> *) a. Monad m => a -> m a return LibraryName LMainLibName parseComposite :: m LibraryName parseComposite = do Char _ <- Char -> m Char forall (m :: * -> *). CharParsing m => Char -> m Char P.char Char ':' UnqualComponentName -> LibraryName LSubLibName (UnqualComponentName -> LibraryName) -> m UnqualComponentName -> m LibraryName forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> m UnqualComponentName forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a parsec defaultLibName :: LibraryName defaultLibName :: LibraryName defaultLibName = LibraryName LMainLibName showLibraryName :: LibraryName -> String showLibraryName :: LibraryName -> String showLibraryName LibraryName LMainLibName = String "library" showLibraryName (LSubLibName UnqualComponentName name) = String "library '" String -> ShowS forall a. [a] -> [a] -> [a] ++ UnqualComponentName -> String forall a. Pretty a => a -> String prettyShow UnqualComponentName name String -> ShowS forall a. [a] -> [a] -> [a] ++ String "'" libraryNameStanza :: LibraryName -> String libraryNameStanza :: LibraryName -> String libraryNameStanza LibraryName LMainLibName = String "library" libraryNameStanza (LSubLibName UnqualComponentName name) = String "library " String -> ShowS forall a. [a] -> [a] -> [a] ++ UnqualComponentName -> String forall a. Pretty a => a -> String prettyShow UnqualComponentName name libraryNameString :: LibraryName -> Maybe UnqualComponentName libraryNameString :: LibraryName -> Maybe UnqualComponentName libraryNameString LibraryName LMainLibName = Maybe UnqualComponentName forall a. Maybe a Nothing libraryNameString (LSubLibName UnqualComponentName n) = UnqualComponentName -> Maybe UnqualComponentName forall a. a -> Maybe a Just UnqualComponentName n -- | Convert the 'UnqualComponentName' of a library into a -- 'LibraryName'. maybeToLibraryName :: Maybe UnqualComponentName -> LibraryName maybeToLibraryName :: Maybe UnqualComponentName -> LibraryName maybeToLibraryName Maybe UnqualComponentName Nothing = LibraryName LMainLibName maybeToLibraryName (Just UnqualComponentName n) = UnqualComponentName -> LibraryName LSubLibName UnqualComponentName n