@@ -1,21 +1,14 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Annotation
2module Reporting.Annotation
3− ( Annotated(..)
3+ ( Located(..)
6− , at, merge, sameAs
4+ , at, merge
7 , map, drop
5 , map, drop
8− , listToDict
6+ , traverse
13−import Prelude hiding (drop, map)
11+import Prelude hiding (drop, map, traverse)
14−import qualified Data.List as List
15−import Data.List.NonEmpty (NonEmpty((:|)))
16−import qualified Data.Map as Map
17−import Data.Semigroup ((<>))
18−import Data.Text (Text)
19import qualified Reporting.Region as R
12import qualified Reporting.Region as R
@@ -23,16 +16,8 @@ import qualified Reporting.Region as R
23-- ANNOTATION
16-- ANNOTATION
26−data Annotated annotation a =
30−type Located a =
19+data Located a =
35− Annotated (R.Region, Maybe Text) a
20+ At R.Region a
@@ -41,41 +26,28 @@ type Commented a =
42at :: R.Position -> R.Position -> a -> Located a
27at :: R.Position -> R.Position -> a -> Located a
43at start end value =
28at start end value =
44− A (R.Region start end) value
29+ At (R.Region start end) value
47merge :: Located a -> Located b -> value -> Located value
32merge :: Located a -> Located b -> value -> Located value
48−merge (A region1 _) (A region2 _) value =
33+merge (At region1 _) (At region2 _) value =
49− A (R.merge region1 region2) value
34+ At (R.merge region1 region2) value
52−sameAs :: Annotated info a -> b -> Annotated info b
53−sameAs (A annotation _) value =
58-- MANIPULATE
38-- MANIPULATE
61−map :: (a -> b) -> Annotated info a -> Annotated info b
41+map :: (a -> b) -> Located a -> Located b
62−map f (A info value) =
42+map f (At info value) =
63− A info (f value)
43+ At info (f value)
66−drop :: Annotated info a -> a
46+drop :: Located a -> a
67−drop (A _ value) =
47+drop (At _ value) =
71−
51+traverse :: (Functor f) => (a -> f b) -> Located a -> f (Located b)
72−-- ANALYZE
52+traverse func (At region value) =
73−
53+ At region <$> func value
75−listToDict :: (Ord key) => (a -> key) -> [Annotated i a] -> Map.Map key (NonEmpty i)
76−listToDict toKey list =
78− add dict (A info value) =
79− Map.insertWith (<>) (toKey value) (info :| []) dict
81− List.foldl' add Map.empty list