checkMapRecover: find undefined idents in all jments in Rename

This commit is contained in:
aarne
2012-06-25 11:14:52 +00:00
parent 3dc2e55949
commit d15e0f775d
2 changed files with 9 additions and 2 deletions

View File

@@ -52,7 +52,7 @@ renameSourceTerm g m t = do
renameModule :: [SourceModule] -> SourceModule -> Check SourceModule
renameModule ms mo@(m,mi) = do
status <- buildStatus (mGrammar ms) mo
js <- checkMap (renameInfo status mo) (jments mi)
js <- checkMapRecover (renameInfo status mo) (jments mi)
return (m, mi{jments = js})
type Status = (StatusTree, [(OpenSpec, StatusTree)])

View File

@@ -15,7 +15,7 @@
module GF.Infra.CheckM
(Check(..), CheckResult(..), Message, runCheck,
checkError, checkCond, checkWarn,
checkErr, checkIn, checkMap
checkErr, checkIn, checkMap, checkMapRecover
) where
import GF.Data.Operations
@@ -65,6 +65,13 @@ checkMap f map = do xs <- mapM (\(k,v) -> do v <- f k v
return (k,v)) (Map.toList map)
return (Map.fromAscList xs)
checkMapRecover :: (Ord a) => (a -> b -> Check b) -> Map.Map a b -> Check (Map.Map a b)
checkMapRecover f mp = do
let xs = map (\ (k,v) -> (k,runCheck (f k v))) (Map.toList mp)
case [s | (_,Bad s) <- xs] of
ss@(_:_) -> checkError (text (unlines ss))
_ -> return (Map.fromAscList [(k,x) | (k, Ok (x,_)) <- xs])
checkErr :: Err a -> Check a
checkErr (Ok x) = return x
checkErr (Bad err) = checkError (text err)