1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 module Distribution
.SPDX
.LicenseExceptionId
(
4 LicenseExceptionId
(..),
10 import Distribution
.Compat
.Prelude
13 import Distribution
.Pretty
14 import Distribution
.Parsec
.Class
15 import Distribution
.Utils
.Generic
(isAsciiAlphaNum
)
17 import qualified Distribution
.Compat
.Map
.Strict
as Map
18 import qualified Distribution
.Compat
.CharParsing
as P
19 import qualified Text
.PrettyPrint
as Disp
21 -------------------------------------------------------------------------------
23 -------------------------------------------------------------------------------
25 -- | SPDX License identifier
26 data LicenseExceptionId
28 deriving (Eq
, Ord
, Enum
, Bounded
, Show, Read, Typeable
, Data
, Generic
)
30 instance Binary LicenseExceptionId
32 instance Pretty LicenseExceptionId
where
33 pretty
= Disp
.text
. licenseExceptionId
35 instance Parsec LicenseExceptionId
where
37 n
<- some
$ P
.satisfy
$ \c
-> isAsciiAlphaNum c || c
== '-' || c
== '.'
38 maybe (fail $ "Unknown SPDX license exception identifier: " ++ n
) return $ mkLicenseExceptionId n
40 instance NFData LicenseExceptionId
where
43 -------------------------------------------------------------------------------
45 -------------------------------------------------------------------------------
47 -- | License SPDX identifier, e.g. @"BSD-3-Clause"@.
48 licenseExceptionId
:: LicenseExceptionId
-> String
50 licenseExceptionId
{{licenseCon
}} = {{{licenseId
}}}
53 -- | License name, e.g. @"GNU General Public License v2.0 only"@
54 licenseExceptionName
:: LicenseExceptionId
-> String
56 licenseExceptionName
{{licenseCon
}} = {{{licenseName
}}}
59 -------------------------------------------------------------------------------
61 -------------------------------------------------------------------------------
63 -- | Create a 'LicenseExceptionId' from a 'String'.
64 mkLicenseExceptionId
:: String -> Maybe LicenseExceptionId
65 mkLicenseExceptionId s
= Map
.lookup s stringLookup
67 stringLookup
:: Map
String LicenseExceptionId
68 stringLookup
= Map
.fromList
$ map (\i
-> (licenseExceptionId i
, i
)) $ [minBound .. maxBound]