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