module Distribution.License (
License(..),
knownLicenses,
) where
import Distribution.Version (Version(Version))
import Distribution.Text (Text(..), display)
import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ((<>))
import qualified Data.Char as Char (isAlphaNum)
data License =
GPL (Maybe Version)
| LGPL (Maybe Version)
| BSD3
| BSD4
| MIT
| PublicDomain
| AllRightsReserved
| OtherLicense
| UnknownLicense String
deriving (D:Read ::
(Int -> ReadS a)
-> ReadS [a]
-> ReadPrec a
-> ReadPrec [a]
-> T:Read aRead, D:Show ::
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow, D:Eq :: (a -> a -> Bool) -> (a -> a -> Bool) -> T:Eq aEq)
knownLicenses :: [License]
knownLicenses = [ GPL :: Maybe Version -> LicenseGPL unversioned :: Maybe aunversioned, GPL :: Maybe Version -> LicenseGPL (version :: Maybe Versionversion [2]), GPL :: Maybe Version -> LicenseGPL (version :: Maybe Versionversion [3])
, LGPL :: Maybe Version -> LicenseLGPL unversioned :: Maybe aunversioned, LGPL :: Maybe Version -> LicenseLGPL (version :: Maybe Versionversion [2,1]), LGPL :: Maybe Version -> LicenseLGPL (version :: Maybe Versionversion [3])
, BSD3 :: LicenseBSD3, MIT :: LicenseMIT
, PublicDomain :: LicensePublicDomain, AllRightsReserved :: LicenseAllRightsReserved, OtherLicense :: LicenseOtherLicense]
where
unversioned = Nothing :: Maybe aNothing
version v = Just :: a -> Maybe aJust (Version :: [Int] -> [String] -> VersionVersion v :: [Int]v [] :: [a][])
instance D:Text :: (a -> Doc) -> (forall r. ReadP r a) -> T:Text aText License where
disp (GPL version) = text :: String -> DocDisp.text "GPL" (<>) :: Doc -> Doc -> Doc<> dispOptVersion :: Maybe Version -> DocdispOptVersion version :: Maybe Versionversion
disp (LGPL version) = text :: String -> DocDisp.text "LGPL" (<>) :: Doc -> Doc -> Doc<> dispOptVersion :: Maybe Version -> DocdispOptVersion version :: Maybe Versionversion
disp (UnknownLicense other) = text :: String -> DocDisp.text other :: Licenseother
disp other = text :: String -> DocDisp.text (show :: Show a => a -> Stringshow other :: Licenseother)
parse = do
name <- munch1 :: (Char -> Bool) -> ReadP r StringParse.munch1 (\c -> isAlphaNum :: Char -> BoolChar.isAlphaNum c :: Charc (&&) :: Bool -> Bool -> Bool&& c :: Charc (/=) :: Eq a => a -> a -> Bool/= '-')
version <- option :: a -> ReadP r a -> ReadP r aParse.option Nothing :: Maybe aNothing (char :: Char -> ReadP r CharParse.char '-' (>>) :: Monad m => forall a b. m a -> m b -> m b>> fmap :: Functor f => forall a b. (a -> b) -> f a -> f bfmap Just :: a -> Maybe aJust parse :: Text a => forall r. ReadP r aparse)
return :: Monad m => forall a. a -> m areturn ($!) :: (a -> b) -> a -> b$! case (name :: Stringname, version :: Maybe Versionversion :: Maybe Version) of
("GPL", _ ) -> GPL :: Maybe Version -> LicenseGPL version :: Maybe Versionversion
("LGPL", _ ) -> LGPL :: Maybe Version -> LicenseLGPL version :: Maybe Versionversion
("BSD3", Nothing) -> BSD3 :: LicenseBSD3
("BSD4", Nothing) -> BSD4 :: LicenseBSD4
("MIT", Nothing) -> MIT :: LicenseMIT
("PublicDomain", Nothing) -> PublicDomain :: LicensePublicDomain
("AllRightsReserved", Nothing) -> AllRightsReserved :: LicenseAllRightsReserved
("OtherLicense", Nothing) -> OtherLicense :: LicenseOtherLicense
_ -> UnknownLicense :: String -> LicenseUnknownLicense ($) :: (a -> b) -> a -> b$ name :: Stringname
(++) :: [a] -> [a] -> [a]++ maybe :: b -> (a -> b) -> Maybe a -> bmaybe "" (('-'(:) :: a -> [a] -> [a]:) (.) :: (b -> c) -> (a -> b) -> a -> c. display :: Text a => a -> Stringdisplay) version :: Maybe Versionversion
dispOptVersion :: Maybe Version -> Disp.Doc
dispOptVersion Nothing = empty :: DocDisp.empty
dispOptVersion (Just v) = char :: Char -> DocDisp.char '-' (<>) :: Doc -> Doc -> Doc<> disp :: Text a => a -> Docdisp v :: [Int]v