{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} module Distribution.Types.LibraryName ( LibraryName (..) , defaultLibName , maybeToLibraryName , showLibraryName , libraryNameStanza , libraryNameString -- * Pretty & Parse , prettyLibraryNameComponent , parsecLibraryNameComponent ) where import Distribution.Compat.Prelude import Prelude () import Distribution.Parsec import Distribution.Pretty import Distribution.Types.UnqualComponentName 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 $c== :: LibraryName -> LibraryName -> Bool == :: LibraryName -> LibraryName -> Bool $c/= :: LibraryName -> LibraryName -> Bool /= :: 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 $cfrom :: forall x. LibraryName -> Rep LibraryName x from :: forall x. LibraryName -> Rep LibraryName x $cto :: forall x. Rep LibraryName x -> LibraryName to :: forall x. Rep LibraryName x -> LibraryName 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 $ccompare :: LibraryName -> LibraryName -> Ordering compare :: LibraryName -> LibraryName -> Ordering $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 >= :: LibraryName -> LibraryName -> Bool $cmax :: LibraryName -> LibraryName -> LibraryName max :: LibraryName -> LibraryName -> LibraryName $cmin :: LibraryName -> LibraryName -> LibraryName min :: LibraryName -> LibraryName -> LibraryName 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 $creadsPrec :: Int -> ReadS LibraryName readsPrec :: Int -> ReadS LibraryName $creadList :: ReadS [LibraryName] readList :: ReadS [LibraryName] $creadPrec :: ReadPrec LibraryName readPrec :: ReadPrec LibraryName $creadListPrec :: ReadPrec [LibraryName] readListPrec :: ReadPrec [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 $cshowsPrec :: Int -> LibraryName -> ShowS showsPrec :: Int -> LibraryName -> ShowS $cshow :: LibraryName -> String show :: LibraryName -> String $cshowList :: [LibraryName] -> ShowS showList :: [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 -> Constr LibraryName -> DataType (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) $cgfoldl :: forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LibraryName -> c LibraryName gfoldl :: forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LibraryName -> c LibraryName $cgunfold :: forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LibraryName gunfold :: forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LibraryName $ctoConstr :: LibraryName -> Constr toConstr :: LibraryName -> Constr $cdataTypeOf :: LibraryName -> DataType dataTypeOf :: LibraryName -> DataType $cdataCast1 :: forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LibraryName) dataCast1 :: forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LibraryName) $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibraryName) dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LibraryName) $cgmapT :: (forall b. Data b => b -> b) -> LibraryName -> LibraryName gmapT :: (forall b. Data b => b -> b) -> LibraryName -> LibraryName $cgmapQl :: 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 $cgmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LibraryName -> r $cgmapQ :: forall u. (forall d. Data d => d -> u) -> LibraryName -> [u] gmapQ :: forall u. (forall d. Data d => d -> u) -> LibraryName -> [u] $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LibraryName -> u gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LibraryName -> u $cgmapM :: forall (m :: * -> *). Monad 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 $cgmapMp :: 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 $cgmapMo :: forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m LibraryName gmapMo :: forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> LibraryName -> m 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 -> m String forall (m :: * -> *). CharParsing m => String -> m String P.string String "lib" parseComposite <|> parseSingle where parseSingle :: m LibraryName parseSingle = LibraryName -> m LibraryName forall a. a -> m a forall (m :: * -> *) a. Monad m => a -> m a return LibraryName LMainLibName parseComposite :: m LibraryName parseComposite = do _ <- Char -> m Char forall (m :: * -> *). CharParsing m => Char -> m Char P.char Char ':' LSubLibName <$> 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