Commit 356f91c5 authored by Robert Henderson's avatar Robert Henderson

Code cleanup: removed duplicated versions of readPToMaybe.

parent 0fba9366
......@@ -36,6 +36,7 @@ module Distribution.ParseUtils (
field, simpleField, listField, listFieldWithSep, spaceListField,
commaListField, commaListFieldWithSep, commaNewLineListField,
optsField, liftField, boolField, parseQuoted, parseMaybeQuoted, indentWith,
readPToMaybe,
UnrecFieldParser, warnUnrec, ignoreUnrec,
) where
......@@ -697,3 +698,7 @@ parseMaybeQuoted p = parseQuoted p <++ p
parseFreeText :: ReadP.ReadP s String
parseFreeText = ReadP.munch (const True)
readPToMaybe :: ReadP a a -> String -> Maybe a
readPToMaybe p str = listToMaybe [ r | (r,s) <- readP_to_S p str
, all isSpace s ]
......@@ -55,6 +55,7 @@ import Distribution.Verbosity
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP ( (+++), (<++) )
import Distribution.ParseUtils ( readPToMaybe )
import Control.Monad ( msum )
import Data.List ( stripPrefix, groupBy, partition )
......@@ -207,10 +208,6 @@ readUserBuildTarget targetstr =
parseHaskellString :: Parse.ReadP r String
parseHaskellString = Parse.readS_to_P reads
readPToMaybe :: Parse.ReadP a a -> String -> Maybe a
readPToMaybe p str = listToMaybe [ r | (r,s) <- Parse.readP_to_S p str
, all isSpace s ]
data UserBuildTargetProblem
= UserBuildTargetUnrecognised String
deriving Show
......
......@@ -82,6 +82,7 @@ import Distribution.Compiler
import Distribution.ReadE
import Distribution.Text
import qualified Distribution.Compat.ReadP as Parse
import Distribution.ParseUtils (readPToMaybe)
import qualified Text.PrettyPrint as Disp
import Distribution.ModuleName
import Distribution.Package
......@@ -2187,10 +2188,6 @@ optionNumJobs get set =
-- * Other Utils
-- ------------------------------------------------------------
readPToMaybe :: Parse.ReadP a a -> String -> Maybe a
readPToMaybe p str = listToMaybe [ r | (r,s) <- Parse.readP_to_S p str
, all isSpace s ]
-- | Arguments to pass to a @configure@ script, e.g. generated by
-- @autoconf@.
configureArgs :: Bool -> ConfigFlags -> [String]
......
......@@ -74,7 +74,7 @@ import Data.Function
import Data.List
( nubBy, stripPrefix, partition, intercalate, sortBy, groupBy )
import Data.Maybe
( listToMaybe, maybeToList )
( maybeToList )
import Data.Ord
( comparing )
import GHC.Generics (Generic)
......@@ -97,6 +97,8 @@ import Control.Applicative (Alternative(..))
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP
( (+++), (<++) )
import Distribution.ParseUtils
( readPToMaybe )
import Data.Char
( isSpace, isAlphaNum )
import System.FilePath as FilePath
......@@ -399,10 +401,6 @@ parseUserBuildTarget targetstr =
parseHaskellString :: Parse.ReadP r String
parseHaskellString = Parse.readS_to_P reads
readPToMaybe :: Parse.ReadP a a -> String -> Maybe a
readPToMaybe p str = listToMaybe [ r | (r,s) <- Parse.readP_to_S p str
, all isSpace s ]
-- | Syntax error when trying to parse a 'UserBuildTarget'.
data UserBuildTargetProblem
= UserBuildTargetUnrecognised String
......
......@@ -93,7 +93,7 @@ import Distribution.Simple.Setup
, Flag(..), toFlag, flagToMaybe, flagToList
, BooleanFlag(..), optionVerbosity
, boolOpt, boolOpt', trueArg, falseArg
, readPToMaybe, optionNumJobs )
, optionNumJobs )
import Distribution.Simple.InstallDirs
( PathTemplate, InstallDirs(dynlibdir, sysconfdir)
, toPathTemplate, fromPathTemplate )
......@@ -111,6 +111,8 @@ import Distribution.ReadE
( ReadE(..), readP_to_E, succeedReadE )
import qualified Distribution.Compat.ReadP as Parse
( ReadP, char, munch1, pfail, (+++) )
import Distribution.ParseUtils
( readPToMaybe )
import Distribution.Verbosity
( Verbosity, lessVerbose, normal )
import Distribution.Simple.Utils
......
......@@ -102,6 +102,8 @@ import Control.Monad (mapM)
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP
( (+++), (<++) )
import Distribution.ParseUtils
( readPToMaybe )
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint
( (<+>) )
......@@ -301,10 +303,6 @@ readUserTarget targetstr =
v | v == nullVersion -> Dependency (packageName p) anyVersion
| otherwise -> Dependency (packageName p) (thisVersion v)
readPToMaybe :: Parse.ReadP a a -> String -> Maybe a
readPToMaybe p str = listToMaybe [ r | (r,s) <- Parse.readP_to_S p str
, all isSpace s ]
reportUserTargetProblems :: [UserTargetProblem] -> IO ()
reportUserTargetProblems problems = do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment