From 46bef1c09f499c5b34a00b650614bebfa1d6ba4b Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Thu, 9 Jul 2009 16:04:12 +0000 Subject: [PATCH] Remove maybePrefixMatch, using stripPrefix instead We already require GHC 6.8 to build, and that included stripPrefix in Data.List. --- compiler/main/CmdLineParser.hs | 4 +++- compiler/main/DynFlags.hs | 4 ++-- compiler/main/Packages.lhs | 4 ++-- compiler/main/StaticFlags.hs | 2 +- compiler/parser/Lexer.x | 4 ++-- compiler/utils/Util.lhs | 11 +---------- 6 files changed, 11 insertions(+), 18 deletions(-) diff --git a/compiler/main/CmdLineParser.hs b/compiler/main/CmdLineParser.hs index dfdea62..dfe756b 100644 --- a/compiler/main/CmdLineParser.hs +++ b/compiler/main/CmdLineParser.hs @@ -23,6 +23,8 @@ import Outputable import Panic import SrcLoc +import Data.List + data Flag m = Flag { flagName :: String, -- flag, without the leading - @@ -118,7 +120,7 @@ findArg spec arg = case [ (removeSpaces rest, optKind, flagDeprecated flag) | flag <- spec, let optKind = flagOptKind flag, - Just rest <- [maybePrefixMatch (flagName flag) arg], + Just rest <- [stripPrefix (flagName flag) arg], arg_ok optKind rest arg ] of [] -> Nothing diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index e39bff3..bebea76 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -92,7 +92,7 @@ import Data.IORef import Control.Monad ( when ) import Data.Char -import Data.List ( intersperse ) +import Data.List import System.FilePath import System.IO ( stderr, hPutChar ) @@ -826,7 +826,7 @@ addDepSuffix s d = d { depSuffixes = deOptDep s : depSuffixes d } -- We used to use "-optdep-flag -optdeparg", so for legacy applications -- we need to strip the "-optdep" off of the arg deOptDep :: String -> String -deOptDep x = case maybePrefixMatch "-optdep" x of +deOptDep x = case stripPrefix "-optdep" x of Just rest -> rest Nothing -> x diff --git a/compiler/main/Packages.lhs b/compiler/main/Packages.lhs index 505a797..bdb8cf7 100644 --- a/compiler/main/Packages.lhs +++ b/compiler/main/Packages.lhs @@ -265,8 +265,8 @@ mungePackagePaths top_dir ps = map munge_pkg ps munge_paths = map munge_path munge_path p - | Just p' <- maybePrefixMatch "$topdir" p = top_dir ++ p' - | Just p' <- maybePrefixMatch "$httptopdir" p = toHttpPath top_dir ++ p' + | Just p' <- stripPrefix "$topdir" p = top_dir ++ p' + | Just p' <- stripPrefix "$httptopdir" p = toHttpPath top_dir ++ p' | otherwise = p toHttpPath p = "file:///" ++ p diff --git a/compiler/main/StaticFlags.hs b/compiler/main/StaticFlags.hs index 3660d37..126b3a0 100644 --- a/compiler/main/StaticFlags.hs +++ b/compiler/main/StaticFlags.hs @@ -134,7 +134,7 @@ lookUp sw = sw `elem` packed_static_opts -- (lookup_str "foo") looks for the flag -foo=X or -fooX, -- and returns the string X lookup_str sw - = case firstJust (map (maybePrefixMatch sw) staticFlags) of + = case firstJust (map (stripPrefix sw) staticFlags) of Just ('=' : str) -> Just str Just str -> Just str Nothing -> Nothing diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index fb7a535..ffabc61 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -65,7 +65,7 @@ import SrcLoc import UniqFM import DynFlags import Ctype -import Util ( maybePrefixMatch, readRational ) +import Util ( readRational ) import Control.Monad import Data.Bits @@ -1323,7 +1323,7 @@ lex_escape = do Just (c3,i3) -> let str = [c1,c2,c3] in case [ (c,rest) | (p,c) <- silly_escape_chars, - Just rest <- [maybePrefixMatch p str] ] of + Just rest <- [stripPrefix p str] ] of (escape_char,[]):_ -> do setInput i3 return escape_char diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs index 62ab5f9..3de52b6 100644 --- a/compiler/utils/Util.lhs +++ b/compiler/utils/Util.lhs @@ -42,7 +42,7 @@ module Util ( -- * Comparisons isEqual, eqListBy, - thenCmp, cmpList, maybePrefixMatch, + thenCmp, cmpList, removeSpaces, -- * Transitive closures @@ -664,15 +664,6 @@ cmpList cmp (a:as) (b:bs) \end{code} \begin{code} --- This (with a more general type) is Data.List.stripPrefix from GHC 6.8. --- This definition can be removed once we require at least 6.8 to build. -maybePrefixMatch :: String -> String -> Maybe String -maybePrefixMatch [] rest = Just rest -maybePrefixMatch (_:_) [] = Nothing -maybePrefixMatch (p:pat) (r:rest) - | p == r = maybePrefixMatch pat rest - | otherwise = Nothing - removeSpaces :: String -> String removeSpaces = reverse . dropWhile isSpace . reverse . dropWhile isSpace \end{code} -- 1.7.10.4