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 qualified Text.PrettyPrint as Disp
data LegacyExeDependency = LegacyExeDependency
String
VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
instance Binary LegacyExeDependency
instance Structured LegacyExeDependency
instance NFData LegacyExeDependency where rnf = genericRnf
instance Pretty LegacyExeDependency where
pretty (LegacyExeDependency name ver) =
Disp.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 "-" <$> toList <$> P.sepByNonEmpty component (P.char '-')
component = do
cs <- P.munch1 (\c -> isAlphaNum c || c == '+' || c == '_')
if all isDigit cs then fail "invalid component" else return cs