Skip to content

Commit cfbf34e

Browse files
committed
Add ErrorRuleMergeDuplicateId
1 parent 11e10fb commit cfbf34e

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{- |
2+
Copyright : (c) Runtime Verification, 2020
3+
License : NCSA
4+
5+
-}
6+
7+
module Kore.Log.ErrorRuleMergeDuplicateId
8+
( ErrorRuleMergeDuplicateId
9+
, errorRuleMergeDuplicateId
10+
) where
11+
12+
import Prelude.Kore
13+
14+
import Control.Exception
15+
( Exception (..)
16+
, throw
17+
)
18+
import qualified Control.Lens as Lens
19+
import Data.Generics.Product
20+
( field
21+
)
22+
import Data.Generics.Wrapped
23+
( _Unwrapped
24+
)
25+
import Data.Text
26+
( Text
27+
)
28+
import qualified Generics.SOP as SOP
29+
import qualified GHC.Generics as GHC
30+
31+
import Kore.Attribute.SourceLocation
32+
( SourceLocation (..)
33+
)
34+
import Kore.Internal.TermLike
35+
( VariableName
36+
)
37+
import Kore.Step.RulePattern
38+
( RewriteRule (..)
39+
)
40+
import Log
41+
import Pretty
42+
( Pretty (..)
43+
)
44+
import qualified Pretty
45+
46+
data ErrorRuleMergeDuplicateId =
47+
ErrorRuleMergeDuplicateId
48+
{ locations :: [SourceLocation]
49+
, ruleId :: Text
50+
}
51+
deriving (Show)
52+
deriving (GHC.Generic)
53+
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
54+
55+
instance Exception ErrorRuleMergeDuplicateId where
56+
toException = toException . SomeEntry
57+
fromException exn =
58+
fromException exn >>= fromEntry
59+
60+
instance Entry ErrorRuleMergeDuplicateId where
61+
entrySeverity _ = Error
62+
helpDoc _ =
63+
"error thrown during rule merging when\
64+
\ multiple rules have the same id"
65+
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+
]
74+
75+
errorRuleMergeDuplicateId :: [RewriteRule VariableName] -> Text -> a
76+
errorRuleMergeDuplicateId rules ruleId =
77+
throw ErrorRuleMergeDuplicateId { locations, ruleId }
78+
where
79+
locations =
80+
Lens.view
81+
( _Unwrapped
82+
. field @"attributes"
83+
. field @"sourceLocation"
84+
)
85+
<$> rules

0 commit comments

Comments
 (0)