diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-05-30 16:45:48 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-05-30 16:45:48 +0000 |
| commit | 3a20b4883d9b2d13e81df17c745071c8c53b2004 (patch) | |
| tree | e5a2e74e233fd625cd306dc6d661c8054f683d85 /src-3.0/GF/Data/Operations.hs | |
| parent | c0ba151aa93d0aad2d616a33b62bbc255174b4b9 (diff) | |
error recovery in rename and check grammar: report all errors in a module before terminating
Diffstat (limited to 'src-3.0/GF/Data/Operations.hs')
| -rw-r--r-- | src-3.0/GF/Data/Operations.hs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src-3.0/GF/Data/Operations.hs b/src-3.0/GF/Data/Operations.hs index 1b2033d69..253723876 100644 --- a/src-3.0/GF/Data/Operations.hs +++ b/src-3.0/GF/Data/Operations.hs @@ -22,7 +22,7 @@ module GF.Data.Operations (-- * misc functions performOps, repeatUntilErr, repeatUntil, okError, isNotError, showBad, lookupErr, lookupErrMsg, lookupDefault, updateLookupList, mapPairListM, mapPairsM, pairM, mapErr, mapErrN, foldErr, - (!?), errList, singleton, + (!?), errList, singleton, mapsErr, mapsErrTree, -- ** checking checkUnique, titleIfNeeded, errMsg, errAndMsg, @@ -183,6 +183,7 @@ mapErrN maxN f xs = Ok (ys, unlines (errHdr : ss2)) nss = length ss fxs = map f xs + -- | like @foldM@, but also return the latest value if fails foldErr :: (a -> b -> Err a) -> a -> [b] -> Err (a, Maybe String) foldErr f s xs = case xs of @@ -630,6 +631,23 @@ instance ErrorMonad (STM s) where `handle` (\e -> let STM g' = (g e) in g' s)) +-- error recovery with multiple reporting AR 30/5/2008 +mapsErr :: (a -> Err b) -> [a] -> Err [b] + +mapsErr f = seqs . map f where + seqs es = case es of + Ok v : ms -> case seqs ms of + Ok vs -> return (v : vs) + b -> b + Bad s : ms -> case seqs ms of + Ok vs -> Bad s + Bad ss -> Bad (s +++++ ss) + [] -> return [] + +mapsErrTree :: (Ord a) => ((a,b) -> Err (a,c)) -> BinTree a b -> Err (BinTree a c) +mapsErrTree f t = mapsErr f (tree2list t) >>= return . sorted2tree + + -- | if the first check fails try another one checkAgain :: ErrorMonad m => m a -> m a -> m a checkAgain c1 c2 = handle_ c1 c2 |
