Cleanup directory compat
[cabal.git] / boot / SPDX.LicenseExceptionId.template.hs
blobdc7f8cc8f7146dffbe289dff1bc2a2af71843d8d
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 module Distribution.SPDX.LicenseExceptionId (
4 LicenseExceptionId (..),
5 licenseExceptionId,
6 licenseExceptionName,
7 mkLicenseExceptionId,
8 ) where
10 import Distribution.Compat.Prelude
11 import 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 -------------------------------------------------------------------------------
22 -- LicenseExceptionId
23 -------------------------------------------------------------------------------
25 -- | SPDX License identifier
26 data LicenseExceptionId
27 {{{ licenseIds }}}
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
36 parsec = do
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
41 rnf l = l `seq` ()
43 -------------------------------------------------------------------------------
44 -- License Data
45 -------------------------------------------------------------------------------
47 -- | License SPDX identifier, e.g. @"BSD-3-Clause"@.
48 licenseExceptionId :: LicenseExceptionId -> String
49 {{#licenses}}
50 licenseExceptionId {{licenseCon}} = {{{licenseId}}}
51 {{/licenses}}
53 -- | License name, e.g. @"GNU General Public License v2.0 only"@
54 licenseExceptionName :: LicenseExceptionId -> String
55 {{#licenses}}
56 licenseExceptionName {{licenseCon}} = {{{licenseName}}}
57 {{/licenses}}
59 -------------------------------------------------------------------------------
60 -- Creation
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]