@@ -5,8 +5,8 @@ License : NCSA
5
5
-}
6
6
7
7
module Kore.Log.ErrorRuleMergeDuplicateId
8
- ( ErrorRuleMergeDuplicateId
9
- , errorRuleMergeDuplicateId
8
+ ( ErrorRuleMergeDuplicateIds
9
+ , errorRuleMergeDuplicateIds
10
10
) where
11
11
12
12
import Prelude.Kore
@@ -22,6 +22,10 @@ import Data.Generics.Product
22
22
import Data.Generics.Wrapped
23
23
( _Unwrapped
24
24
)
25
+ import Data.Map.Strict
26
+ ( Map
27
+ )
28
+ import qualified Data.Map.Strict as Map
25
29
import Data.Text
26
30
( Text
27
31
)
@@ -43,43 +47,48 @@ import Pretty
43
47
)
44
48
import qualified Pretty
45
49
46
- data ErrorRuleMergeDuplicateId =
47
- ErrorRuleMergeDuplicateId
48
- { locations :: [SourceLocation ]
49
- , ruleId :: Text
50
+ newtype ErrorRuleMergeDuplicateIds =
51
+ ErrorRuleMergeDuplicateIds
52
+ { unErrorRuleMergeDuplicateIds :: Map Text [SourceLocation ]
50
53
}
51
54
deriving (Show )
52
55
deriving (GHC.Generic )
53
56
deriving anyclass (SOP.Generic , SOP.HasDatatypeInfo )
54
57
55
- instance Exception ErrorRuleMergeDuplicateId where
58
+ instance Exception ErrorRuleMergeDuplicateIds where
56
59
toException = toException . SomeEntry
57
60
fromException exn =
58
61
fromException exn >>= fromEntry
59
62
60
- instance Entry ErrorRuleMergeDuplicateId where
63
+ instance Entry ErrorRuleMergeDuplicateIds where
61
64
entrySeverity _ = Error
62
65
helpDoc _ =
63
66
" error thrown during rule merging when\
64
67
\ multiple rules have the same id"
65
68
66
- instance Pretty ErrorRuleMergeDuplicateId where
67
- pretty ErrorRuleMergeDuplicateId { locations , ruleId } =
68
- Pretty. vsep
69
- $ [" The rules at the following locations:" ]
70
- <> fmap (Pretty. indent 4 . pretty) locations
71
- <> [ Pretty. indent 2 " all have the following id:"
72
- , Pretty. indent 4 (pretty ruleId)
73
- ]
69
+ instance Pretty ErrorRuleMergeDuplicateIds where
70
+ pretty (ErrorRuleMergeDuplicateIds duplicateIds) =
71
+ Map. foldMapWithKey accum duplicateIds
72
+ where
73
+ accum ruleId locations =
74
+ Pretty. vsep
75
+ $ [" The rules at the following locations:" ]
76
+ <> fmap (Pretty. indent 4 . pretty) locations
77
+ <> [ Pretty. indent 2 " all have the following id:"
78
+ , Pretty. indent 4 (pretty ruleId)
79
+ ]
74
80
75
- errorRuleMergeDuplicateId :: [RewriteRule VariableName ] -> Text -> a
76
- errorRuleMergeDuplicateId rules ruleId =
77
- throw ErrorRuleMergeDuplicateId { locations, ruleId }
81
+ errorRuleMergeDuplicateIds :: Map Text [RewriteRule VariableName ] -> a
82
+ errorRuleMergeDuplicateIds duplicateIds =
83
+ throw ( ErrorRuleMergeDuplicateIds idsWithlocations)
78
84
where
79
- locations =
80
- Lens. view
81
- ( _Unwrapped
82
- . field @ " attributes"
83
- . field @ " sourceLocation"
84
- )
85
- <$> rules
85
+ idsWithlocations =
86
+ (fmap . fmap )
87
+ (
88
+ Lens. view
89
+ ( _Unwrapped
90
+ . field @ " attributes"
91
+ . field @ " sourceLocation"
92
+ )
93
+ )
94
+ duplicateIds
0 commit comments