{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.LegacyExeDependency
( LegacyExeDependency(..)
) where
import Distribution.Compat.Prelude
import Prelude ()
import Distribution.Parsec
import Distribution.Pretty
import Distribution.Version (VersionRange, anyVersion)
import qualified Distribution.Compat.CharParsing as P
import Text.PrettyPrint (text, (<+>))
data LegacyExeDependency = LegacyExeDependency
String
VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
instance Binary LegacyExeDependency
instance NFData LegacyExeDependency where rnf = genericRnf
instance Pretty LegacyExeDependency where
pretty (LegacyExeDependency name ver) =
text name <+> pretty ver
instance Parsec LegacyExeDependency where
parsec = do
name <- parsecMaybeQuoted nameP
P.spaces
verRange <- parsecMaybeQuoted parsec <|> pure anyVersion
pure $ LegacyExeDependency name verRange
where
nameP = intercalate "-" <$> P.sepBy1 component (P.char '-')
component = do
cs <- P.munch1 (\c -> isAlphaNum c || c == '+' || c == '_')
if all isDigit cs then fail "invalid component" else return cs