module Distribution.SPDX (
LicenseId
, LicenseExceptionId
, LicenseRef(..)
, LicenseExpression(..)
, licenseIdentifiers
, licenseExceptions
, licenseRanges
, lookupLicenseRange
, parseExpression
, unsafeParseExpr
, satisfies
) where
import Distribution.SPDX.Types
import Distribution.SPDX.Ranges
import Distribution.SPDX.Licenses
import Distribution.SPDX.Parser
import Distribution.SPDX.LatticeSyntax
data Lic = Lic (Either LicenseRef String) (Maybe String)
deriving (Eq, Ord, Show, Read)
exprToLSLic :: LicenseExpression -> LatticeSyntax Lic
exprToLSLic (ELicense False l e) = LVar (Lic l e)
exprToLSLic (ELicense True (Right l) e) = foldr1 LJoin $ map (\l' -> LVar $ Lic (Right l') e) $ lookupLicenseRange l
exprToLSLic (ELicense True (Left l) e) = LVar (Lic (Left l) e)
exprToLSLic (EConjunction a b) = LMeet (exprToLSLic a) (exprToLSLic b)
exprToLSLic (EDisjunction a b) = LJoin (exprToLSLic a) (exprToLSLic b)
satisfies :: LicenseExpression
-> LicenseExpression
-> Bool
satisfies a b = exprToLSLic b `preorder` exprToLSLic a