Hack to get the compare tool to work on Windows "bindists"
[ghc-hetmet.git] / distrib / compare / Utils.hs
1
2 module Utils where
3
4 import System.Exit
5 import System.IO
6 import Text.Regex.Posix
7
8 die :: Errors -> IO a
9 die errs = do mapM_ (hPutStrLn stderr) errs
10               exitFailure
11
12 dieOnErrors :: Either Errors a -> IO a
13 dieOnErrors (Left errs) = die errs
14 dieOnErrors (Right x) = return x
15
16 type Errors = [String]
17
18 maybeRead :: Read a => String -> Maybe a
19 maybeRead str = case reads str of
20                 [(x, "")] -> Just x
21                 _ -> Nothing
22
23 re :: String -> String -> Maybe [String]
24 re r str = case matchM r' str :: Maybe (String, String, String, [String]) of
25            Just (_, _, _, ms) -> Just ms
26            Nothing -> Nothing
27     where r' = makeRegex r :: Regex
28
29 unSepList :: Eq a => a -> [a] -> [[a]]
30 unSepList x xs = case break (x ==) xs of
31                  (this, _ : xs') ->
32                      this : unSepList x xs'
33                  (this, []) ->
34                      [this]
35