module Agda.Interaction.Highlighting.Precise
(
Aspect(..)
, NameKind(..)
, OtherAspect(..)
, Aspects(..)
, DefinitionSite(..)
, TokenBased(..)
, RangePair(..)
, rangePairInvariant
, PositionMap(..)
, DelayedMerge(..)
, delayedMergeInvariant
, HighlightingInfo
, highlightingInfoInvariant
, HighlightingInfoBuilder
, highlightingInfoBuilderInvariant
, parserBased
, kindOfNameToNameKind
, IsBasicRangeMap(..)
, RangeMap.several
, Convert(..)
, RangeMap.insideAndOutside
, RangeMap.restrictTo
) where
import Prelude hiding (null)
import Control.Arrow (second)
import Control.DeepSeq
import Control.Monad
import Data.Function
import qualified Data.List as List
import Data.Maybe
import Data.Semigroup
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
import GHC.Generics (Generic)
import qualified Agda.Syntax.Position as P
import qualified Agda.Syntax.Common as Common
import Agda.Syntax.TopLevelModuleName
import Agda.Syntax.Scope.Base ( KindOfName(..) )
import Agda.Interaction.Highlighting.Range
import Agda.Utils.List
import qualified Agda.Utils.List1 as List1
import Agda.Utils.Maybe
import Agda.Utils.Null
import Agda.Utils.RangeMap (RangeMap, IsBasicRangeMap(..))
import qualified Agda.Utils.RangeMap as RangeMap
import Agda.Utils.String
import Agda.Utils.Impossible
data Aspect
=
| Keyword
| String
| Number
| Hole
| Symbol
| PrimitiveType
| Name (Maybe NameKind) Bool
| Pragma
| Background
| Markup
deriving (Aspect -> Aspect -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Aspect -> Aspect -> Bool
$c/= :: Aspect -> Aspect -> Bool
== :: Aspect -> Aspect -> Bool
$c== :: Aspect -> Aspect -> Bool
Eq, Int -> Aspect -> ShowS
[Aspect] -> ShowS
Aspect -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Aspect] -> ShowS
$cshowList :: [Aspect] -> ShowS
show :: Aspect -> String
$cshow :: Aspect -> String
showsPrec :: Int -> Aspect -> ShowS
$cshowsPrec :: Int -> Aspect -> ShowS
Show, forall x. Rep Aspect x -> Aspect
forall x. Aspect -> Rep Aspect x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Aspect x -> Aspect
$cfrom :: forall x. Aspect -> Rep Aspect x
Generic)
data NameKind
= Bound
| Generalizable
| Constructor Common.Induction
| Datatype
| Field
| Function
| Module
| Postulate
| Primitive
| Record
| Argument
| Macro
deriving (NameKind -> NameKind -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NameKind -> NameKind -> Bool
$c/= :: NameKind -> NameKind -> Bool
== :: NameKind -> NameKind -> Bool
$c== :: NameKind -> NameKind -> Bool
Eq, Int -> NameKind -> ShowS
[NameKind] -> ShowS
NameKind -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NameKind] -> ShowS
$cshowList :: [NameKind] -> ShowS
show :: NameKind -> String
$cshow :: NameKind -> String
showsPrec :: Int -> NameKind -> ShowS
$cshowsPrec :: Int -> NameKind -> ShowS
Show, forall x. Rep NameKind x -> NameKind
forall x. NameKind -> Rep NameKind x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NameKind x -> NameKind
$cfrom :: forall x. NameKind -> Rep NameKind x
Generic)
data OtherAspect
= Error
| ErrorWarning
| DottedPattern
| UnsolvedMeta
| UnsolvedConstraint
| TerminationProblem
| PositivityProblem
| Deadcode
| ShadowingInTelescope
| CoverageProblem
| IncompletePattern
| TypeChecks
| MissingDefinition
| CatchallClause
| ConfluenceProblem
deriving (OtherAspect -> OtherAspect -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OtherAspect -> OtherAspect -> Bool
$c/= :: OtherAspect -> OtherAspect -> Bool
== :: OtherAspect -> OtherAspect -> Bool
$c== :: OtherAspect -> OtherAspect -> Bool
Eq, Eq OtherAspect
OtherAspect -> OtherAspect -> Bool
OtherAspect -> OtherAspect -> Ordering
OtherAspect -> OtherAspect -> OtherAspect
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: OtherAspect -> OtherAspect -> OtherAspect
$cmin :: OtherAspect -> OtherAspect -> OtherAspect
max :: OtherAspect -> OtherAspect -> OtherAspect
$cmax :: OtherAspect -> OtherAspect -> OtherAspect
>= :: OtherAspect -> OtherAspect -> Bool
$c>= :: OtherAspect -> OtherAspect -> Bool
> :: OtherAspect -> OtherAspect -> Bool
$c> :: OtherAspect -> OtherAspect -> Bool
<= :: OtherAspect -> OtherAspect -> Bool
$c<= :: OtherAspect -> OtherAspect -> Bool
< :: OtherAspect -> OtherAspect -> Bool
$c< :: OtherAspect -> OtherAspect -> Bool
compare :: OtherAspect -> OtherAspect -> Ordering
$ccompare :: OtherAspect -> OtherAspect -> Ordering
Ord, Int -> OtherAspect -> ShowS
[OtherAspect] -> ShowS
OtherAspect -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OtherAspect] -> ShowS
$cshowList :: [OtherAspect] -> ShowS
show :: OtherAspect -> String
$cshow :: OtherAspect -> String
showsPrec :: Int -> OtherAspect -> ShowS
$cshowsPrec :: Int -> OtherAspect -> ShowS
Show, Int -> OtherAspect
OtherAspect -> Int
OtherAspect -> [OtherAspect]
OtherAspect -> OtherAspect
OtherAspect -> OtherAspect -> [OtherAspect]
OtherAspect -> OtherAspect -> OtherAspect -> [OtherAspect]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: OtherAspect -> OtherAspect -> OtherAspect -> [OtherAspect]
$cenumFromThenTo :: OtherAspect -> OtherAspect -> OtherAspect -> [OtherAspect]
enumFromTo :: OtherAspect -> OtherAspect -> [OtherAspect]
$cenumFromTo :: OtherAspect -> OtherAspect -> [OtherAspect]
enumFromThen :: OtherAspect -> OtherAspect -> [OtherAspect]
$cenumFromThen :: OtherAspect -> OtherAspect -> [OtherAspect]
enumFrom :: OtherAspect -> [OtherAspect]
$cenumFrom :: OtherAspect -> [OtherAspect]
fromEnum :: OtherAspect -> Int
$cfromEnum :: OtherAspect -> Int
toEnum :: Int -> OtherAspect
$ctoEnum :: Int -> OtherAspect
pred :: OtherAspect -> OtherAspect
$cpred :: OtherAspect -> OtherAspect
succ :: OtherAspect -> OtherAspect
$csucc :: OtherAspect -> OtherAspect
Enum, OtherAspect
forall a. a -> a -> Bounded a
maxBound :: OtherAspect
$cmaxBound :: OtherAspect
minBound :: OtherAspect
$cminBound :: OtherAspect
Bounded, forall x. Rep OtherAspect x -> OtherAspect
forall x. OtherAspect -> Rep OtherAspect x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OtherAspect x -> OtherAspect
$cfrom :: forall x. OtherAspect -> Rep OtherAspect x
Generic)
data Aspects = Aspects
{ Aspects -> Maybe Aspect
aspect :: Maybe Aspect
, Aspects -> Set OtherAspect
otherAspects :: Set OtherAspect
, Aspects -> String
note :: String
, Aspects -> Maybe DefinitionSite
definitionSite :: Maybe DefinitionSite
, Aspects -> TokenBased
tokenBased :: !TokenBased
}
deriving (Int -> Aspects -> ShowS
[Aspects] -> ShowS
Aspects -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Aspects] -> ShowS
$cshowList :: [Aspects] -> ShowS
show :: Aspects -> String
$cshow :: Aspects -> String
showsPrec :: Int -> Aspects -> ShowS
$cshowsPrec :: Int -> Aspects -> ShowS
Show, forall x. Rep Aspects x -> Aspects
forall x. Aspects -> Rep Aspects x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Aspects x -> Aspects
$cfrom :: forall x. Aspects -> Rep Aspects x
Generic)
data DefinitionSite = DefinitionSite
{ DefinitionSite -> TopLevelModuleName
defSiteModule :: TopLevelModuleName
, DefinitionSite -> Int
defSitePos :: Int
, DefinitionSite -> Bool
defSiteHere :: Bool
, DefinitionSite -> Maybe String
defSiteAnchor :: Maybe String
}
deriving (Int -> DefinitionSite -> ShowS
[DefinitionSite] -> ShowS
DefinitionSite -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DefinitionSite] -> ShowS
$cshowList :: [DefinitionSite] -> ShowS
show :: DefinitionSite -> String
$cshow :: DefinitionSite -> String
showsPrec :: Int -> DefinitionSite -> ShowS
$cshowsPrec :: Int -> DefinitionSite -> ShowS
Show, forall x. Rep DefinitionSite x -> DefinitionSite
forall x. DefinitionSite -> Rep DefinitionSite x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DefinitionSite x -> DefinitionSite
$cfrom :: forall x. DefinitionSite -> Rep DefinitionSite x
Generic)
instance Eq DefinitionSite where
DefinitionSite TopLevelModuleName
m Int
p Bool
_ Maybe String
_ == :: DefinitionSite -> DefinitionSite -> Bool
== DefinitionSite TopLevelModuleName
m' Int
p' Bool
_ Maybe String
_ = TopLevelModuleName
m forall a. Eq a => a -> a -> Bool
== TopLevelModuleName
m' Bool -> Bool -> Bool
&& Int
p forall a. Eq a => a -> a -> Bool
== Int
p'
data TokenBased = TokenBased | NotOnlyTokenBased
deriving (TokenBased -> TokenBased -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TokenBased -> TokenBased -> Bool
$c/= :: TokenBased -> TokenBased -> Bool
== :: TokenBased -> TokenBased -> Bool
$c== :: TokenBased -> TokenBased -> Bool
Eq, Int -> TokenBased -> ShowS
[TokenBased] -> ShowS
TokenBased -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TokenBased] -> ShowS
$cshowList :: [TokenBased] -> ShowS
show :: TokenBased -> String
$cshow :: TokenBased -> String
showsPrec :: Int -> TokenBased -> ShowS
$cshowsPrec :: Int -> TokenBased -> ShowS
Show)
instance Eq Aspects where
Aspects Maybe Aspect
a Set OtherAspect
o String
_ Maybe DefinitionSite
d TokenBased
t == :: Aspects -> Aspects -> Bool
== Aspects Maybe Aspect
a' Set OtherAspect
o' String
_ Maybe DefinitionSite
d' TokenBased
t' =
(Maybe Aspect
a, Set OtherAspect
o, Maybe DefinitionSite
d, TokenBased
t) forall a. Eq a => a -> a -> Bool
== (Maybe Aspect
a', Set OtherAspect
o', Maybe DefinitionSite
d', TokenBased
t')
newtype RangePair = RangePair
{ RangePair -> (Ranges, Aspects)
rangePair :: (Ranges, Aspects)
}
deriving (Int -> RangePair -> ShowS
[RangePair] -> ShowS
RangePair -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RangePair] -> ShowS
$cshowList :: [RangePair] -> ShowS
show :: RangePair -> String
$cshow :: RangePair -> String
showsPrec :: Int -> RangePair -> ShowS
$cshowsPrec :: Int -> RangePair -> ShowS
Show, RangePair -> ()
forall a. (a -> ()) -> NFData a
rnf :: RangePair -> ()
$crnf :: RangePair -> ()
NFData)
rangePairInvariant :: RangePair -> Bool
rangePairInvariant :: RangePair -> Bool
rangePairInvariant (RangePair (Ranges
rs, Aspects
_)) =
Ranges -> Bool
rangesInvariant Ranges
rs
newtype PositionMap = PositionMap
{ PositionMap -> IntMap Aspects
positionMap :: IntMap Aspects
}
deriving (Int -> PositionMap -> ShowS
[PositionMap] -> ShowS
PositionMap -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PositionMap] -> ShowS
$cshowList :: [PositionMap] -> ShowS
show :: PositionMap -> String
$cshow :: PositionMap -> String
showsPrec :: Int -> PositionMap -> ShowS
$cshowsPrec :: Int -> PositionMap -> ShowS
Show, PositionMap -> ()
forall a. (a -> ()) -> NFData a
rnf :: PositionMap -> ()
$crnf :: PositionMap -> ()
NFData)
newtype DelayedMerge hl = DelayedMerge (Endo [hl])
deriving (NonEmpty (DelayedMerge hl) -> DelayedMerge hl
DelayedMerge hl -> DelayedMerge hl -> DelayedMerge hl
forall b. Integral b => b -> DelayedMerge hl -> DelayedMerge hl
forall hl. NonEmpty (DelayedMerge hl) -> DelayedMerge hl
forall hl. DelayedMerge hl -> DelayedMerge hl -> DelayedMerge hl
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall hl b. Integral b => b -> DelayedMerge hl -> DelayedMerge hl
stimes :: forall b. Integral b => b -> DelayedMerge hl -> DelayedMerge hl
$cstimes :: forall hl b. Integral b => b -> DelayedMerge hl -> DelayedMerge hl
sconcat :: NonEmpty (DelayedMerge hl) -> DelayedMerge hl
$csconcat :: forall hl. NonEmpty (DelayedMerge hl) -> DelayedMerge hl
<> :: DelayedMerge hl -> DelayedMerge hl -> DelayedMerge hl
$c<> :: forall hl. DelayedMerge hl -> DelayedMerge hl -> DelayedMerge hl
Semigroup, DelayedMerge hl
[DelayedMerge hl] -> DelayedMerge hl
DelayedMerge hl -> DelayedMerge hl -> DelayedMerge hl
forall hl. Semigroup (DelayedMerge hl)
forall hl. DelayedMerge hl
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall hl. [DelayedMerge hl] -> DelayedMerge hl
forall hl. DelayedMerge hl -> DelayedMerge hl -> DelayedMerge hl
mconcat :: [DelayedMerge hl] -> DelayedMerge hl
$cmconcat :: forall hl. [DelayedMerge hl] -> DelayedMerge hl
mappend :: DelayedMerge hl -> DelayedMerge hl -> DelayedMerge hl
$cmappend :: forall hl. DelayedMerge hl -> DelayedMerge hl -> DelayedMerge hl
mempty :: DelayedMerge hl
$cmempty :: forall hl. DelayedMerge hl
Monoid)
instance Show hl => Show (DelayedMerge hl) where
showsPrec :: Int -> DelayedMerge hl -> ShowS
showsPrec Int
_ (DelayedMerge Endo [hl]
f) =
String -> ShowS
showString String
"DelayedMerge (Endo (" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Show a => a -> ShowS
shows (forall a. Endo a -> a -> a
appEndo Endo [hl]
f []) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ShowS
showString String
" ++))"
delayedMergeInvariant :: (hl -> Bool) -> DelayedMerge hl -> Bool
delayedMergeInvariant :: forall hl. (hl -> Bool) -> DelayedMerge hl -> Bool
delayedMergeInvariant hl -> Bool
inv (DelayedMerge Endo [hl]
f) =
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all hl -> Bool
inv (forall a. Endo a -> a -> a
appEndo Endo [hl]
f [])
type HighlightingInfo = RangeMap Aspects
highlightingInfoInvariant :: HighlightingInfo -> Bool
highlightingInfoInvariant :: HighlightingInfo -> Bool
highlightingInfoInvariant = forall a. RangeMap a -> Bool
RangeMap.rangeMapInvariant
type HighlightingInfoBuilder = DelayedMerge RangePair
highlightingInfoBuilderInvariant :: HighlightingInfoBuilder -> Bool
highlightingInfoBuilderInvariant :: DelayedMerge RangePair -> Bool
highlightingInfoBuilderInvariant =
forall hl. (hl -> Bool) -> DelayedMerge hl -> Bool
delayedMergeInvariant RangePair -> Bool
rangePairInvariant
parserBased :: Aspects
parserBased :: Aspects
parserBased = forall a. Monoid a => a
mempty { tokenBased :: TokenBased
tokenBased = TokenBased
NotOnlyTokenBased }
kindOfNameToNameKind :: KindOfName -> NameKind
kindOfNameToNameKind :: KindOfName -> NameKind
kindOfNameToNameKind = \case
KindOfName
ConName -> Induction -> NameKind
Constructor Induction
Common.Inductive
KindOfName
CoConName -> Induction -> NameKind
Constructor Induction
Common.CoInductive
KindOfName
FldName -> NameKind
Field
KindOfName
PatternSynName -> Induction -> NameKind
Constructor Induction
Common.Inductive
KindOfName
GeneralizeName -> NameKind
Generalizable
KindOfName
DisallowedGeneralizeName -> NameKind
Generalizable
KindOfName
MacroName -> NameKind
Macro
KindOfName
QuotableName -> NameKind
Function
KindOfName
DataName -> NameKind
Datatype
KindOfName
RecName -> NameKind
Record
KindOfName
FunName -> NameKind
Function
KindOfName
AxiomName -> NameKind
Postulate
KindOfName
PrimName -> NameKind
Primitive
KindOfName
OtherDefName -> NameKind
Function
instance IsBasicRangeMap Aspects RangePair where
singleton :: Ranges -> Aspects -> RangePair
singleton Ranges
rs Aspects
m = (Ranges, Aspects) -> RangePair
RangePair (Ranges
rs, Aspects
m)
toList :: RangePair -> [(Range, Aspects)]
toList (RangePair (Ranges [Range]
rs, Aspects
m)) =
[ (Range
r, Aspects
m) | Range
r <- [Range]
rs, Bool -> Bool
not (forall a. Null a => a -> Bool
null Range
r) ]
toMap :: RangePair -> IntMap Aspects
toMap RangePair
f = forall a m. IsBasicRangeMap a m => m -> IntMap a
toMap (forall a b. Convert a b => a -> b
convert (forall hl. Endo [hl] -> DelayedMerge hl
DelayedMerge (forall a. (a -> a) -> Endo a
Endo (RangePair
f forall a. a -> [a] -> [a]
:))) :: PositionMap)
instance IsBasicRangeMap Aspects PositionMap where
singleton :: Ranges -> Aspects -> PositionMap
singleton Ranges
rs Aspects
m = PositionMap
{ positionMap :: IntMap Aspects
positionMap =
forall a. [(Int, a)] -> IntMap a
IntMap.fromDistinctAscList [ (Int
p, Aspects
m) | Int
p <- Ranges -> [Int]
rangesToPositions Ranges
rs ]
}
toList :: PositionMap -> [(Range, Aspects)]
toList = forall a b. (a -> b) -> [a] -> [b]
map forall {b}. NonEmpty (Int, b) -> (Range, b)
join forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> a -> Bool) -> [a] -> [List1 a]
List1.groupBy' forall {a} {a}. (Num a, Eq a, Eq a) => (a, a) -> (a, a) -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IntMap a -> [(Int, a)]
IntMap.toAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. PositionMap -> IntMap Aspects
positionMap
where
p :: (a, a) -> (a, a) -> Bool
p (a
pos1, a
m1) (a
pos2, a
m2) = a
pos2 forall a. Eq a => a -> a -> Bool
== a
pos1 forall a. Num a => a -> a -> a
+ a
1 Bool -> Bool -> Bool
&& a
m1 forall a. Eq a => a -> a -> Bool
== a
m2
join :: NonEmpty (Int, b) -> (Range, b)
join NonEmpty (Int, b)
pms = ( Range { from :: Int
from = forall a. NonEmpty a -> a
List1.head NonEmpty Int
ps, to :: Int
to = forall a. NonEmpty a -> a
List1.last NonEmpty Int
ps forall a. Num a => a -> a -> a
+ Int
1 }
, forall a. NonEmpty a -> a
List1.head NonEmpty b
ms
)
where (NonEmpty Int
ps, NonEmpty b
ms) = forall (f :: * -> *) a b. Functor f => f (a, b) -> (f a, f b)
List1.unzip NonEmpty (Int, b)
pms
toMap :: PositionMap -> IntMap Aspects
toMap = PositionMap -> IntMap Aspects
positionMap
instance Semigroup a =>
IsBasicRangeMap a (DelayedMerge (RangeMap a)) where
singleton :: Ranges -> a -> DelayedMerge (RangeMap a)
singleton Ranges
r a
m = forall hl. Endo [hl] -> DelayedMerge hl
DelayedMerge (forall a. (a -> a) -> Endo a
Endo (forall a m. IsBasicRangeMap a m => Ranges -> a -> m
singleton Ranges
r a
m forall a. a -> [a] -> [a]
:))
toMap :: DelayedMerge (RangeMap a) -> IntMap a
toMap DelayedMerge (RangeMap a)
f = forall a m. IsBasicRangeMap a m => m -> IntMap a
toMap (forall a b. Convert a b => a -> b
convert DelayedMerge (RangeMap a)
f :: RangeMap a)
toList :: DelayedMerge (RangeMap a) -> [(Range, a)]
toList DelayedMerge (RangeMap a)
f = forall a m. IsBasicRangeMap a m => m -> [(Range, a)]
toList (forall a b. Convert a b => a -> b
convert DelayedMerge (RangeMap a)
f :: RangeMap a)
instance IsBasicRangeMap Aspects (DelayedMerge RangePair) where
singleton :: Ranges -> Aspects -> DelayedMerge RangePair
singleton Ranges
r Aspects
m = forall hl. Endo [hl] -> DelayedMerge hl
DelayedMerge (forall a. (a -> a) -> Endo a
Endo (forall a m. IsBasicRangeMap a m => Ranges -> a -> m
singleton Ranges
r Aspects
m forall a. a -> [a] -> [a]
:))
toMap :: DelayedMerge RangePair -> IntMap Aspects
toMap DelayedMerge RangePair
f = forall a m. IsBasicRangeMap a m => m -> IntMap a
toMap (forall a b. Convert a b => a -> b
convert DelayedMerge RangePair
f :: PositionMap)
toList :: DelayedMerge RangePair -> [(Range, Aspects)]
toList DelayedMerge RangePair
f = forall a m. IsBasicRangeMap a m => m -> [(Range, a)]
toList (forall a b. Convert a b => a -> b
convert DelayedMerge RangePair
f :: RangeMap Aspects)
instance IsBasicRangeMap Aspects (DelayedMerge PositionMap) where
singleton :: Ranges -> Aspects -> DelayedMerge PositionMap
singleton Ranges
r Aspects
m = forall hl. Endo [hl] -> DelayedMerge hl
DelayedMerge (forall a. (a -> a) -> Endo a
Endo (forall a m. IsBasicRangeMap a m => Ranges -> a -> m
singleton Ranges
r Aspects
m forall a. a -> [a] -> [a]
:))
toMap :: DelayedMerge PositionMap -> IntMap Aspects
toMap DelayedMerge PositionMap
f = forall a m. IsBasicRangeMap a m => m -> IntMap a
toMap (forall a b. Convert a b => a -> b
convert DelayedMerge PositionMap
f :: PositionMap)
toList :: DelayedMerge PositionMap -> [(Range, Aspects)]
toList DelayedMerge PositionMap
f = forall a m. IsBasicRangeMap a m => m -> [(Range, a)]
toList (forall a b. Convert a b => a -> b
convert DelayedMerge PositionMap
f :: PositionMap)
class Convert a b where
convert :: a -> b
instance Monoid hl => Convert (DelayedMerge hl) hl where
convert :: DelayedMerge hl -> hl
convert (DelayedMerge Endo [hl]
f) = forall a. Monoid a => [a] -> a
mconcat (forall a. Endo a -> a -> a
appEndo Endo [hl]
f [])
instance Convert (RangeMap Aspects) (RangeMap Aspects) where
convert :: HighlightingInfo -> HighlightingInfo
convert = forall a. a -> a
id
instance Convert PositionMap (RangeMap Aspects) where
convert :: PositionMap -> HighlightingInfo
convert =
forall a. [(Range, a)] -> RangeMap a
RangeMap.fromNonOverlappingNonEmptyAscendingList forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a m. IsBasicRangeMap a m => m -> [(Range, a)]
toList
instance Convert (DelayedMerge PositionMap) (RangeMap Aspects) where
convert :: DelayedMerge PositionMap -> HighlightingInfo
convert DelayedMerge PositionMap
f = forall a b. Convert a b => a -> b
convert (forall a b. Convert a b => a -> b
convert DelayedMerge PositionMap
f :: PositionMap)
instance Convert (DelayedMerge RangePair) PositionMap where
convert :: DelayedMerge RangePair -> PositionMap
convert (DelayedMerge Endo [RangePair]
f) =
IntMap Aspects -> PositionMap
PositionMap forall a b. (a -> b) -> a -> b
$
forall a. (a -> a -> a) -> [(Int, a)] -> IntMap a
IntMap.fromListWith (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Semigroup a => a -> a -> a
(<>))
[ (Int
p, Aspects
m)
| RangePair (Ranges
r, Aspects
m) <- forall a. Endo a -> a -> a
appEndo Endo [RangePair]
f []
, Int
p <- Ranges -> [Int]
rangesToPositions Ranges
r
]
instance Convert (DelayedMerge RangePair) (RangeMap Aspects) where
convert :: DelayedMerge RangePair -> HighlightingInfo
convert (DelayedMerge Endo [RangePair]
f) =
forall a. Monoid a => [a] -> a
mconcat
[ forall a m. IsBasicRangeMap a m => Ranges -> a -> m
singleton Ranges
r Aspects
m
| RangePair (Ranges
r, Aspects
m) <- forall a. Endo a -> a -> a
appEndo Endo [RangePair]
f []
]
instance Semigroup TokenBased where
b1 :: TokenBased
b1@TokenBased
NotOnlyTokenBased <> :: TokenBased -> TokenBased -> TokenBased
<> TokenBased
b2 = TokenBased
b1
TokenBased
TokenBased <> TokenBased
b2 = TokenBased
b2
instance Monoid TokenBased where
mempty :: TokenBased
mempty = TokenBased
TokenBased
mappend :: TokenBased -> TokenBased -> TokenBased
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup NameKind where
NameKind
Field <> :: NameKind -> NameKind -> NameKind
<> NameKind
Bound = NameKind
Field
NameKind
Bound <> NameKind
Field = NameKind
Field
NameKind
k1 <> NameKind
k2 | NameKind
k1 forall a. Eq a => a -> a -> Bool
== NameKind
k2 = NameKind
k1
| Bool
otherwise = NameKind
k1
instance Semigroup Aspect where
Name Maybe NameKind
mk1 Bool
op1 <> :: Aspect -> Aspect -> Aspect
<> Name Maybe NameKind
mk2 Bool
op2 = Maybe NameKind -> Bool -> Aspect
Name (forall a. (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
unionMaybeWith forall a. Semigroup a => a -> a -> a
(<>) Maybe NameKind
mk1 Maybe NameKind
mk2) Bool
op1
Aspect
a1 <> Aspect
a2 | Aspect
a1 forall a. Eq a => a -> a -> Bool
== Aspect
a2 = Aspect
a1
| Bool
otherwise = Aspect
a1
instance Semigroup DefinitionSite where
DefinitionSite
d1 <> :: DefinitionSite -> DefinitionSite -> DefinitionSite
<> DefinitionSite
d2 | DefinitionSite
d1 forall a. Eq a => a -> a -> Bool
== DefinitionSite
d2 = DefinitionSite
d1
| Bool
otherwise = DefinitionSite
d1
mergeAspects :: Aspects -> Aspects -> Aspects
mergeAspects :: Aspects -> Aspects -> Aspects
mergeAspects Aspects
m1 Aspects
m2 = Aspects
{ aspect :: Maybe Aspect
aspect = (forall a. (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
unionMaybeWith forall a. Semigroup a => a -> a -> a
(<>) forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Aspects -> Maybe Aspect
aspect) Aspects
m1 Aspects
m2
, otherAspects :: Set OtherAspect
otherAspects = (forall a. Ord a => Set a -> Set a -> Set a
Set.union forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Aspects -> Set OtherAspect
otherAspects) Aspects
m1 Aspects
m2
, note :: String
note = case (Aspects -> String
note Aspects
m1, Aspects -> String
note Aspects
m2) of
(String
n1, String
"") -> String
n1
(String
"", String
n2) -> String
n2
(String
n1, String
n2)
| String
n1 forall a. Eq a => a -> a -> Bool
== String
n2 -> String
n1
| Bool
otherwise -> ShowS
addFinalNewLine String
n1 forall a. [a] -> [a] -> [a]
++ String
"----\n" forall a. [a] -> [a] -> [a]
++ String
n2
, definitionSite :: Maybe DefinitionSite
definitionSite = (forall a. (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
unionMaybeWith forall a. Semigroup a => a -> a -> a
(<>) forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Aspects -> Maybe DefinitionSite
definitionSite) Aspects
m1 Aspects
m2
, tokenBased :: TokenBased
tokenBased = Aspects -> TokenBased
tokenBased Aspects
m1 forall a. Semigroup a => a -> a -> a
<> Aspects -> TokenBased
tokenBased Aspects
m2
}
instance Semigroup Aspects where
<> :: Aspects -> Aspects -> Aspects
(<>) = Aspects -> Aspects -> Aspects
mergeAspects
instance Monoid Aspects where
mempty :: Aspects
mempty = Aspects
{ aspect :: Maybe Aspect
aspect = forall a. Maybe a
Nothing
, otherAspects :: Set OtherAspect
otherAspects = forall a. Set a
Set.empty
, note :: String
note = []
, definitionSite :: Maybe DefinitionSite
definitionSite = forall a. Maybe a
Nothing
, tokenBased :: TokenBased
tokenBased = forall a. Monoid a => a
mempty
}
mappend :: Aspects -> Aspects -> Aspects
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup PositionMap where
PositionMap
f1 <> :: PositionMap -> PositionMap -> PositionMap
<> PositionMap
f2 = PositionMap
{ positionMap :: IntMap Aspects
positionMap = (forall a. (a -> a -> a) -> IntMap a -> IntMap a -> IntMap a
IntMap.unionWith forall a. Monoid a => a -> a -> a
mappend forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` PositionMap -> IntMap Aspects
positionMap) PositionMap
f1 PositionMap
f2 }
instance Monoid PositionMap where
mempty :: PositionMap
mempty = PositionMap { positionMap :: IntMap Aspects
positionMap = forall a. IntMap a
IntMap.empty }
mappend :: PositionMap -> PositionMap -> PositionMap
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance NFData Aspect
instance NFData NameKind
instance NFData OtherAspect
instance NFData DefinitionSite
instance NFData Aspects where
rnf :: Aspects -> ()
rnf (Aspects Maybe Aspect
a Set OtherAspect
b String
c Maybe DefinitionSite
d TokenBased
_) = forall a. NFData a => a -> ()
rnf Maybe Aspect
a seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Set OtherAspect
b seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf String
c seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Maybe DefinitionSite
d