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