diff options
| author | hallgren <hallgren@chalmers.se> | 2012-06-26 14:46:18 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2012-06-26 14:46:18 +0000 |
| commit | b094274c0e6e0218977a65821066a3970254810a (patch) | |
| tree | e5cdbb20a5fb276aec6e081802c163fcb213ad91 /src/compiler/GF/Data | |
| parent | a38efe70c6aa340242cb25c3b8fd2845f98b1bb8 (diff) | |
Report many type errors instead of stopping after the first one
In GF.Compile.CheckGrammar, use a new topological sorting function that
groups independent judgements, allowing them all to be checked before
continuing or reporting errors.
Diffstat (limited to 'src/compiler/GF/Data')
| -rw-r--r-- | src/compiler/GF/Data/Operations.hs | 18 | ||||
| -rw-r--r-- | src/compiler/GF/Data/Relation.hs | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/compiler/GF/Data/Operations.hs b/src/compiler/GF/Data/Operations.hs index 7b2afc9fe..781f0a133 100644 --- a/src/compiler/GF/Data/Operations.hs +++ b/src/compiler/GF/Data/Operations.hs @@ -43,7 +43,7 @@ module GF.Data.Operations (-- * misc functions combinations, -- * topological sorting with test of cyclicity - topoTest, + topoTest, topoTest2, -- * the generic fix point iterator iterFix, @@ -60,7 +60,7 @@ module GF.Data.Operations (-- * misc functions ) where import Data.Char (isSpace, toUpper, isSpace, isDigit) -import Data.List (nub, sortBy, sort, deleteBy, nubBy) +import Data.List (nub, sortBy, sort, deleteBy, nubBy, partition, (\\)) import qualified Data.Map as Map import Data.Map (Map) import Control.Monad (liftM,liftM2, MonadPlus, mzero, mplus) @@ -267,6 +267,20 @@ combinations t = case t of topoTest :: Ord a => [(a,[a])] -> Either [a] [[a]] topoTest = topologicalSort . mkRel' +-- | topological sorting with test of cyclicity, new version /TH 2012-06-26 +topoTest2 :: Ord a => [(a,[a])] -> Either [[a]] [[a]] +topoTest2 g = maybe (Right cycles) Left (tsort g) + where + cycles = findCycles (mkRel' g) + + tsort nes = + case partition (null.snd) nes of + ([],[]) -> Just [] + ([],_) -> Nothing + (ns,rest) -> (leaves:) `fmap` tsort [(n,es \\ leaves) | (n,es)<-rest] + where leaves = map fst ns + + -- | the generic fix point iterator iterFix :: Eq a => ([a] -> [a]) -> [a] -> [a] iterFix more start = iter start start diff --git a/src/compiler/GF/Data/Relation.hs b/src/compiler/GF/Data/Relation.hs index 7024a482c..b888a0fd7 100644 --- a/src/compiler/GF/Data/Relation.hs +++ b/src/compiler/GF/Data/Relation.hs @@ -23,7 +23,7 @@ module GF.Data.Relation (Rel, mkRel, mkRel' , isTransitive, isReflexive, isSymmetric , isEquivalence , isSubRelationOf - , topologicalSort) where + , topologicalSort, findCycles) where import Data.Foldable (toList) import Data.List |
