make LTS branch pre-releases
[cabal.git] / Cabal-syntax / src / Distribution / Types / PackageName.hs
blob4cf9d1aeb59fae49f1da05fa4567c3edb67320de
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 module Distribution.Types.PackageName
6 ( PackageName
7 , unPackageName
8 , mkPackageName
9 , unPackageNameST
10 , mkPackageNameST
11 ) where
13 import Distribution.Compat.Prelude
14 import Distribution.Utils.ShortText
15 import Prelude ()
17 import Distribution.Parsec
18 import Distribution.Pretty
19 import qualified Text.PrettyPrint as Disp
21 -- | A package name.
23 -- Use 'mkPackageName' and 'unPackageName' to convert from/to a
24 -- 'String'.
26 -- This type is opaque since @Cabal-2.0@
28 -- @since 2.0.0.2
29 newtype PackageName = PackageName ShortText
30 deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
32 -- | Convert 'PackageName' to 'String'
33 unPackageName :: PackageName -> String
34 unPackageName (PackageName s) = fromShortText s
36 -- | @since 3.4.0.0
37 unPackageNameST :: PackageName -> ShortText
38 unPackageNameST (PackageName s) = s
40 -- | Construct a 'PackageName' from a 'String'
42 -- 'mkPackageName' is the inverse to 'unPackageName'
44 -- Note: No validations are performed to ensure that the resulting
45 -- 'PackageName' is valid
47 -- @since 2.0.0.2
48 mkPackageName :: String -> PackageName
49 mkPackageName = PackageName . toShortText
51 -- | Construct a 'PackageName' from a 'ShortText'
53 -- Note: No validations are performed to ensure that the resulting
54 -- 'PackageName' is valid
56 -- @since 3.4.0.0
57 mkPackageNameST :: ShortText -> PackageName
58 mkPackageNameST = PackageName
60 -- | 'mkPackageName'
62 -- @since 2.0.0.2
63 instance IsString PackageName where
64 fromString = mkPackageName
66 instance Binary PackageName
67 instance Structured PackageName
69 instance Pretty PackageName where
70 pretty = Disp.text . unPackageName
72 instance Parsec PackageName where
73 parsec = mkPackageName <$> parsecUnqualComponentName
75 instance NFData PackageName where
76 rnf (PackageName pkg) = rnf pkg