Merge pull request #10634 from cabalism/hlint/unused-lang-pragma
[cabal.git] / Cabal-syntax / src / Distribution / SPDX / License.hs
blobaf271e9115ad5675aaa99aa770e945fab5f65bda
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution.SPDX.License
5 ( License (..)
6 ) where
8 import Distribution.Compat.Prelude
9 import Prelude ()
11 import Distribution.Parsec
12 import Distribution.Pretty
13 import Distribution.SPDX.LicenseExpression
15 import qualified Distribution.Compat.CharParsing as P
16 import qualified Text.PrettyPrint as Disp
18 -- | Declared license.
19 -- See [section 3.15 of SPDX Specification 2.1](https://spdx.org/spdx-specification-21-web-version#h.1hmsyys)
21 -- /Note:/ the NOASSERTION case is omitted.
23 -- Old 'License' can be migrated using following rules:
25 -- * @AllRightsReserved@ and @UnspecifiedLicense@ to 'NONE'.
26 -- No license specified which legally defaults to /All Rights Reserved/.
27 -- The package may not be legally modified or redistributed by anyone but
28 -- the rightsholder.
30 -- * @OtherLicense@ can be converted to 'LicenseRef' pointing to the file
31 -- in the package.
33 -- * @UnknownLicense@ i.e. other licenses of the form @name-x.y@, should be
34 -- covered by SPDX license list, otherwise use 'LicenseRef'.
36 -- * @PublicDomain@ isn't covered. Consider using CC0.
37 -- See <https://wiki.spdx.org/view/Legal_Team/Decisions/Dealing_with_Public_Domain_within_SPDX_Files>
38 -- for more information.
39 data License
40 = -- | if the package contains no license information whatsoever; or
41 NONE
42 | -- | A valid SPDX License Expression as defined in Appendix IV.
43 License LicenseExpression
44 deriving (Show, Read, Eq, Ord, Typeable, Data, Generic)
46 instance Binary License
47 instance Structured License
49 instance NFData License where
50 rnf NONE = ()
51 rnf (License l) = rnf l
53 instance Pretty License where
54 pretty NONE = Disp.text "NONE"
55 pretty (License l) = pretty l
57 -- |
58 -- >>> eitherParsec "BSD-3-Clause AND MIT" :: Either String License
59 -- Right (License (EAnd (ELicense (ELicenseId BSD_3_Clause) Nothing) (ELicense (ELicenseId MIT) Nothing)))
61 -- >>> eitherParsec "NONE" :: Either String License
62 -- Right NONE
63 instance Parsec License where
64 parsec = NONE <$ P.try (P.string "NONE") <|> License <$> parsec