From d15e0f775d0eeb82e322f715d9e2a55d90206615 Mon Sep 17 00:00:00 2001 From: aarne Date: Mon, 25 Jun 2012 11:14:52 +0000 Subject: [PATCH] checkMapRecover: find undefined idents in all jments in Rename --- src/compiler/GF/Compile/Rename.hs | 2 +- src/compiler/GF/Infra/CheckM.hs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/compiler/GF/Compile/Rename.hs b/src/compiler/GF/Compile/Rename.hs index 32ba76f9b..aeaf3b250 100644 --- a/src/compiler/GF/Compile/Rename.hs +++ b/src/compiler/GF/Compile/Rename.hs @@ -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)]) diff --git a/src/compiler/GF/Infra/CheckM.hs b/src/compiler/GF/Infra/CheckM.hs index 7a5ac2d45..c1198dea6 100644 --- a/src/compiler/GF/Infra/CheckM.hs +++ b/src/compiler/GF/Infra/CheckM.hs @@ -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)