Data.SPDX

spdx-0.2.1.0: SPDX license expression language

Copyright | (c) 2015 Oleg Grenrus
License | BSD3
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi>
Safe Haskell | Safe
Language | Haskell98

Data.SPDX

Contents

- Types
- Data
  - Ranges
- Parsing
- Prettifying
- Logic

Description

Synopsis

- data LicenseId
- getLicenseId :: LicenseId -> String
- data LicenseExceptionId
- getLicenseExceptionId :: LicenseExceptionId -> String
- data LicenseRef = LicenseRef {
  - lrDocument :: !(Maybe String)
  - lrLicense :: !String
  }
- data LicenseExpression
  - = ELicense !Bool !(Either LicenseRef LicenseId) !(Maybe LicenseExceptionId)
  - | EConjunction !LicenseExpression !LicenseExpression
  - | EDisjunction !LicenseExpression !LicenseExpression
- licenses :: [(LicenseId, String, Bool)]
- licenseIdentifiers :: [LicenseId]
- mkLicenseId :: String -> Maybe LicenseId
- isOsiApproved :: LicenseId -> Bool
- licenseExceptions :: [LicenseExceptionId]
- licenseRanges :: [[LicenseId]]
- lookupLicenseRange :: LicenseId -> [LicenseId]
- parseExpression :: String -> [LicenseExpression]
- unsafeParseExpr :: String -> LicenseExpression
- prettyLicenseId :: LicenseId -> String
- prettyLicenseExceptionId :: LicenseExceptionId -> String
- prettyLicenseRef :: LicenseRef -> String
- prettyLicenseExpression :: LicenseExpression -> String
- satisfies :: LicenseExpression -> LicenseExpression -> Bool
- equivalent :: LicenseExpression -> LicenseExpression -> Bool

# Types

data LicenseId #

Opaque license identifier type.

Instances

Eq LicenseId # |
Methods (==) :: LicenseId -> LicenseId -> Bool # (/=) :: LicenseId -> LicenseId -> Bool #
Data LicenseId # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LicenseId -> c LicenseId # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LicenseId # toConstr :: LicenseId -> Constr # dataTypeOf :: LicenseId -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c LicenseId) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LicenseId) # gmapT :: (forall b. Data b => b -> b) -> LicenseId -> LicenseId # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LicenseId -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LicenseId -> r # gmapQ :: (forall d. Data d => d -> u) -> LicenseId -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LicenseId -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LicenseId -> m LicenseId # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LicenseId -> m LicenseId # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LicenseId -> m LicenseId #
Ord LicenseId # |
Methods compare :: LicenseId -> LicenseId -> Ordering # (<) :: LicenseId -> LicenseId -> Bool # (<=) :: LicenseId -> LicenseId -> Bool # (>) :: LicenseId -> LicenseId -> Bool # (>=) :: LicenseId -> LicenseId -> Bool # max :: LicenseId -> LicenseId -> LicenseId # min :: LicenseId -> LicenseId -> LicenseId #
Read LicenseId # |
Methods readsPrec :: Int -> ReadS LicenseId # readList :: ReadS [LicenseId] # readPrec :: ReadPrec LicenseId # readListPrec :: ReadPrec [LicenseId] #
Show LicenseId # |
Methods showsPrec :: Int -> LicenseId -> ShowS # show :: LicenseId -> String # showList :: [LicenseId] -> ShowS #
Generic LicenseId # |
Associated Types type Rep LicenseId :: * -> * # Methods from :: LicenseId -> Rep LicenseId x # to :: Rep LicenseId x -> LicenseId #
type Rep LicenseId # |
type Rep LicenseId = D1 (MetaData "LicenseId" "Data.SPDX.Types" "spdx-0.2.1.0-FfSJSxjLlLfJujpegNlGpH" True) (C1 (MetaCons "LicenseId" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)))

getLicenseId :: LicenseId -> String #

data LicenseExceptionId #

Opaque license exception identifier type.

Instances

Eq LicenseExceptionId # |
Methods (==) :: LicenseExceptionId -> LicenseExceptionId -> Bool # (/=) :: LicenseExceptionId -> LicenseExceptionId -> Bool #
Data LicenseExceptionId # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LicenseExceptionId -> c LicenseExceptionId # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LicenseExceptionId # toConstr :: LicenseExceptionId -> Constr # dataTypeOf :: LicenseExceptionId -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c LicenseExceptionId) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LicenseExceptionId) # gmapT :: (forall b. Data b => b -> b) -> LicenseExceptionId -> LicenseExceptionId # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LicenseExceptionId -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LicenseExceptionId -> r # gmapQ :: (forall d. Data d => d -> u) -> LicenseExceptionId -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LicenseExceptionId -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LicenseExceptionId -> m LicenseExceptionId # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LicenseExceptionId -> m LicenseExceptionId # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LicenseExceptionId -> m LicenseExceptionId #
Ord LicenseExceptionId # |
Methods compare :: LicenseExceptionId -> LicenseExceptionId -> Ordering # (<) :: LicenseExceptionId -> LicenseExceptionId -> Bool # (<=) :: LicenseExceptionId -> LicenseExceptionId -> Bool # (>) :: LicenseExceptionId -> LicenseExceptionId -> Bool # (>=) :: LicenseExceptionId -> LicenseExceptionId -> Bool # max :: LicenseExceptionId -> LicenseExceptionId -> LicenseExceptionId # min :: LicenseExceptionId -> LicenseExceptionId -> LicenseExceptionId #
Read LicenseExceptionId # |
Methods readsPrec :: Int -> ReadS LicenseExceptionId # readList :: ReadS [LicenseExceptionId] # readPrec :: ReadPrec LicenseExceptionId # readListPrec :: ReadPrec [LicenseExceptionId] #
Show LicenseExceptionId # |
Methods showsPrec :: Int -> LicenseExceptionId -> ShowS # show :: LicenseExceptionId -> String # showList :: [LicenseExceptionId] -> ShowS #
Generic LicenseExceptionId # |
Associated Types type Rep LicenseExceptionId :: * -> * # Methods from :: LicenseExceptionId -> Rep LicenseExceptionId x # to :: Rep LicenseExceptionId x -> LicenseExceptionId #
type Rep LicenseExceptionId # |
type Rep LicenseExceptionId = D1 (MetaData "LicenseExceptionId" "Data.SPDX.Types" "spdx-0.2.1.0-FfSJSxjLlLfJujpegNlGpH" True) (C1 (MetaCons "LicenseExceptionId" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)))

getLicenseExceptionId :: LicenseExceptionId -> String #

data LicenseRef #

Constructors

LicenseRef |
Fields lrDocument :: !(Maybe String) lrLicense :: !String

Instances

Eq LicenseRef # |
Methods (==) :: LicenseRef -> LicenseRef -> Bool # (/=) :: LicenseRef -> LicenseRef -> Bool #
Data LicenseRef # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LicenseRef -> c LicenseRef # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LicenseRef # toConstr :: LicenseRef -> Constr # dataTypeOf :: LicenseRef -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c LicenseRef) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LicenseRef) # gmapT :: (forall b. Data b => b -> b) -> LicenseRef -> LicenseRef # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LicenseRef -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LicenseRef -> r # gmapQ :: (forall d. Data d => d -> u) -> LicenseRef -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LicenseRef -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LicenseRef -> m LicenseRef # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LicenseRef -> m LicenseRef # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LicenseRef -> m LicenseRef #
Ord LicenseRef # |
Methods compare :: LicenseRef -> LicenseRef -> Ordering # (<) :: LicenseRef -> LicenseRef -> Bool # (<=) :: LicenseRef -> LicenseRef -> Bool # (>) :: LicenseRef -> LicenseRef -> Bool # (>=) :: LicenseRef -> LicenseRef -> Bool # max :: LicenseRef -> LicenseRef -> LicenseRef # min :: LicenseRef -> LicenseRef -> LicenseRef #
Read LicenseRef # |
Methods readsPrec :: Int -> ReadS LicenseRef # readList :: ReadS [LicenseRef] # readPrec :: ReadPrec LicenseRef # readListPrec :: ReadPrec [LicenseRef] #
Show LicenseRef # |
Methods showsPrec :: Int -> LicenseRef -> ShowS # show :: LicenseRef -> String # showList :: [LicenseRef] -> ShowS #
Generic LicenseRef # |
Associated Types type Rep LicenseRef :: * -> * # Methods from :: LicenseRef -> Rep LicenseRef x # to :: Rep LicenseRef x -> LicenseRef #
type Rep LicenseRef # |
type Rep LicenseRef = D1 (MetaData "LicenseRef" "Data.SPDX.Types" "spdx-0.2.1.0-FfSJSxjLlLfJujpegNlGpH" False) (C1 (MetaCons "LicenseRef" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "lrDocument") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe String))) (S1 (MetaSel (Just Symbol "lrLicense") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 String))))

data LicenseExpression #

Constructors

ELicense !Bool !(Either LicenseRef LicenseId) !(Maybe LicenseExceptionId) |
EConjunction !LicenseExpression !LicenseExpression |
EDisjunction !LicenseExpression !LicenseExpression |

Instances

Eq LicenseExpression # |
Methods (==) :: LicenseExpression -> LicenseExpression -> Bool # (/=) :: LicenseExpression -> LicenseExpression -> Bool #
Data LicenseExpression # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LicenseExpression -> c LicenseExpression # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LicenseExpression # toConstr :: LicenseExpression -> Constr # dataTypeOf :: LicenseExpression -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c LicenseExpression) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LicenseExpression) # gmapT :: (forall b. Data b => b -> b) -> LicenseExpression -> LicenseExpression # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LicenseExpression -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LicenseExpression -> r # gmapQ :: (forall d. Data d => d -> u) -> LicenseExpression -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LicenseExpression -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LicenseExpression -> m LicenseExpression # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LicenseExpression -> m LicenseExpression # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LicenseExpression -> m LicenseExpression #
Ord LicenseExpression # |
Methods compare :: LicenseExpression -> LicenseExpression -> Ordering # (<) :: LicenseExpression -> LicenseExpression -> Bool # (<=) :: LicenseExpression -> LicenseExpression -> Bool # (>) :: LicenseExpression -> LicenseExpression -> Bool # (>=) :: LicenseExpression -> LicenseExpression -> Bool # max :: LicenseExpression -> LicenseExpression -> LicenseExpression # min :: LicenseExpression -> LicenseExpression -> LicenseExpression #
Read LicenseExpression # |
Methods readsPrec :: Int -> ReadS LicenseExpression # readList :: ReadS [LicenseExpression] # readPrec :: ReadPrec LicenseExpression # readListPrec :: ReadPrec [LicenseExpression] #
Show LicenseExpression # |
Methods showsPrec :: Int -> LicenseExpression -> ShowS # show :: LicenseExpression -> String # showList :: [LicenseExpression] -> ShowS #
Generic LicenseExpression # |
Associated Types type Rep LicenseExpression :: * -> * # Methods from :: LicenseExpression -> Rep LicenseExpression x # to :: Rep LicenseExpression x -> LicenseExpression #
type Rep LicenseExpression # |
type Rep LicenseExpression = D1 (MetaData "LicenseExpression" "Data.SPDX.Types" "spdx-0.2.1.0-FfSJSxjLlLfJujpegNlGpH" False) ((:+:) (C1 (MetaCons "ELicense" PrefixI False) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Bool)) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Either LicenseRef LicenseId))) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe LicenseExceptionId)))))) ((:+:) (C1 (MetaCons "EConjunction" PrefixI False) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 LicenseExpression)) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 LicenseExpression)))) (C1 (MetaCons "EDisjunction" PrefixI False) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 LicenseExpression)) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 LicenseExpression))))))

# Data

licenses :: [(LicenseId, String, Bool)] #

A list of `LicenseId`, license name and whether the license is OSI approved.

See http://spdx.org/licenses/.

licenseIdentifiers :: [LicenseId] #

A list of SPDX licenses identifiers.

See http://spdx.org/licenses/.

mkLicenseId :: String -> Maybe LicenseId #

Lookup `LicenseId` by string representation

isOsiApproved :: LicenseId -> Bool #

Whether license is OSI approved

See http://opensource.org/licenses/alphabetical

licenseExceptions :: [LicenseExceptionId] #

## Ranges

licenseRanges :: [[LicenseId]] #

lookupLicenseRange :: LicenseId -> [LicenseId] #

Lookup newer licenses we know about

    >>> lookupLicenseRange $ fromJust $ mkLicenseId "MIT"
    [LicenseId "MIT"]

    >>> lookupLicenseRange $ fromJust $ mkLicenseId "GPL-2.0"
    [LicenseId "GPL-2.0",LicenseId "GPL-3.0"]

    >>> lookupLicenseRange $ fromJust $ mkLicenseId "LGPL-2.0"
    [LicenseId "LGPL-2.0",LicenseId "LGPL-2.1",LicenseId "LGPL-3.0"]

# Parsing

parseExpression :: String -> [LicenseExpression] #

Parse SPDX License Expression

    >>> parseExpression "LGPL-2.1 OR MIT"
    [EDisjunction (ELicense False (Right (LicenseId "LGPL-2.1")) Nothing) (ELicense False (Right (LicenseId "MIT")) Nothing)]

unsafeParseExpr :: String -> LicenseExpression #

# Prettifying

Inverse of parsing

prettyLicenseId :: LicenseId -> String #

prettyLicenseExceptionId :: LicenseExceptionId -> String #

prettyLicenseRef :: LicenseRef -> String #

prettyLicenseExpression :: LicenseExpression -> String #

# Logic

satisfies #

Arguments

:: LicenseExpression | package license
-> LicenseExpression | license policy
-> Bool |

    ⟦ satisfies a b ⟧ ≡ a ≥ b ≡ a ∧ b = b

    >>> unsafeParseExpr "GPL-3.0" `satisfies` unsafeParseExpr "ISC AND MIT"
    False

    >>> unsafeParseExpr "Zlib" `satisfies` unsafeParseExpr "ISC AND MIT AND Zlib"
    True

    >>> unsafeParseExpr "(MIT OR GPL-2.0)" `satisfies` unsafeParseExpr "(ISC AND MIT)"
    True

    >>> unsafeParseExpr "(MIT AND GPL-2.0)" `satisfies` unsafeParseExpr "(MIT AND GPL-2.0)"
    True

    >>> unsafeParseExpr "(MIT AND GPL-2.0)" `satisfies` unsafeParseExpr "(ISC AND GPL-2.0)"
    False

equivalent :: LicenseExpression -> LicenseExpression -> Bool #

Check wheather two `LicenseExpression` are equivalent.

    >>> unsafeParseExpr "(MIT AND GPL-2.0)" `equivalent` unsafeParseExpr "(GPL-2.0 AND MIT)"
    True

    >>> unsafeParseExpr "MIT" `equivalent` unsafeParseExpr "MIT OR BSD-3-Clause"
    False