1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution
.Types
.LibraryName
13 , prettyLibraryNameComponent
14 , parsecLibraryNameComponent
17 import Distribution
.Compat
.Prelude
20 import Distribution
.Parsec
21 import Distribution
.Pretty
22 import Distribution
.Types
.UnqualComponentName
24 import qualified Distribution
.Compat
.CharParsing
as P
25 import qualified Text
.PrettyPrint
as Disp
29 | LSubLibName UnqualComponentName
30 deriving (Eq
, Generic
, Ord
, Read, Show, Typeable
, Data
)
32 instance Binary LibraryName
33 instance Structured LibraryName
34 instance NFData LibraryName
where rnf
= genericRnf
36 -- | Pretty print 'LibraryName' in build-target-ish syntax.
38 -- /Note:/ there are no 'Pretty' or 'Parsec' instances,
39 -- as there's other way to represent 'LibraryName', namely as bare
40 -- 'UnqualComponentName'.
41 prettyLibraryNameComponent
:: LibraryName
-> Disp
.Doc
42 prettyLibraryNameComponent LMainLibName
= Disp
.text
"lib"
43 prettyLibraryNameComponent
(LSubLibName str
) = Disp
.text
"lib:" <<>> pretty str
45 parsecLibraryNameComponent
:: CabalParsing m
=> m LibraryName
46 parsecLibraryNameComponent
= do
48 parseComposite
<|
> parseSingle
50 parseSingle
= return LMainLibName
53 LSubLibName
<$> parsec
55 defaultLibName
:: LibraryName
56 defaultLibName
= LMainLibName
58 showLibraryName
:: LibraryName
-> String
59 showLibraryName LMainLibName
= "library"
60 showLibraryName
(LSubLibName name
) = "library '" ++ prettyShow name
++ "'"
62 libraryNameStanza
:: LibraryName
-> String
63 libraryNameStanza LMainLibName
= "library"
64 libraryNameStanza
(LSubLibName name
) = "library " ++ prettyShow name
66 libraryNameString
:: LibraryName
-> Maybe UnqualComponentName
67 libraryNameString LMainLibName
= Nothing
68 libraryNameString
(LSubLibName n
) = Just n
70 -- | Convert the 'UnqualComponentName' of a library into a
72 maybeToLibraryName
:: Maybe UnqualComponentName
-> LibraryName
73 maybeToLibraryName Nothing
= LMainLibName
74 maybeToLibraryName
(Just n
) = LSubLibName n