{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.LegacyExeDependency
( LegacyExeDependency(..)
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Version ( VersionRange, anyVersion )
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP
import Distribution.Text
import Text.PrettyPrint ((<+>), text)
import Distribution.ParseUtils (parseMaybeQuoted)
data LegacyExeDependency = LegacyExeDependency
String
VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
instance Binary LegacyExeDependency
instance NFData LegacyExeDependency where rnf = genericRnf
instance Text LegacyExeDependency where
disp (LegacyExeDependency name ver) =
text name <+> disp ver
parse = do name <- parseMaybeQuoted parseBuildToolName
Parse.skipSpaces
ver <- parse <++ return anyVersion
Parse.skipSpaces
return $ LegacyExeDependency name ver
where
parseBuildToolName :: Parse.ReadP r String
parseBuildToolName = do ns <- sepBy1 component (Parse.char '-')
return (intercalate "-" ns)
where component = do
cs <- munch1 (\c -> isAlphaNum c || c == '+' || c == '_')
if all isDigit cs then pfail else return cs