{-# LANGUAGE TemplateHaskell, GeneralizedNewtypeDeriving, RankNTypes, DataKinds #-}
module Text.Pandoc.CrossRef.References.Types where
import Data.Default
import qualified Data.Map as M
import Data.Text (Text)
import Lens.Micro.GHC
import Lens.Micro.TH
import Text.Pandoc.Definition
import qualified Data.Sequence as S
type Index = S.Seq (Int, Maybe Text)
data RefRec = RefRec { RefRec -> Index
refIndex :: Index
, RefRec -> [Inline]
refTitle :: [Inline]
, RefRec -> Maybe Index
refSubfigure :: Maybe Index
} deriving (Int -> RefRec -> ShowS
[RefRec] -> ShowS
RefRec -> String
(Int -> RefRec -> ShowS)
-> (RefRec -> String) -> ([RefRec] -> ShowS) -> Show RefRec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RefRec -> ShowS
showsPrec :: Int -> RefRec -> ShowS
$cshow :: RefRec -> String
show :: RefRec -> String
$cshowList :: [RefRec] -> ShowS
showList :: [RefRec] -> ShowS
Show, RefRec -> RefRec -> Bool
(RefRec -> RefRec -> Bool)
-> (RefRec -> RefRec -> Bool) -> Eq RefRec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RefRec -> RefRec -> Bool
== :: RefRec -> RefRec -> Bool
$c/= :: RefRec -> RefRec -> Bool
/= :: RefRec -> RefRec -> Bool
Eq)
type RefMap = M.Map Text RefRec
data Prefix
= PfxImg
| PfxEqn
| PfxTbl
| PfxLst
| PfxSec
deriving (Prefix -> Prefix -> Bool
(Prefix -> Prefix -> Bool)
-> (Prefix -> Prefix -> Bool) -> Eq Prefix
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Prefix -> Prefix -> Bool
== :: Prefix -> Prefix -> Bool
$c/= :: Prefix -> Prefix -> Bool
/= :: Prefix -> Prefix -> Bool
Eq, Eq Prefix
Eq Prefix =>
(Prefix -> Prefix -> Ordering)
-> (Prefix -> Prefix -> Bool)
-> (Prefix -> Prefix -> Bool)
-> (Prefix -> Prefix -> Bool)
-> (Prefix -> Prefix -> Bool)
-> (Prefix -> Prefix -> Prefix)
-> (Prefix -> Prefix -> Prefix)
-> Ord Prefix
Prefix -> Prefix -> Bool
Prefix -> Prefix -> Ordering
Prefix -> Prefix -> Prefix
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
$ccompare :: Prefix -> Prefix -> Ordering
compare :: Prefix -> Prefix -> Ordering
$c< :: Prefix -> Prefix -> Bool
< :: Prefix -> Prefix -> Bool
$c<= :: Prefix -> Prefix -> Bool
<= :: Prefix -> Prefix -> Bool
$c> :: Prefix -> Prefix -> Bool
> :: Prefix -> Prefix -> Bool
$c>= :: Prefix -> Prefix -> Bool
>= :: Prefix -> Prefix -> Bool
$cmax :: Prefix -> Prefix -> Prefix
max :: Prefix -> Prefix -> Prefix
$cmin :: Prefix -> Prefix -> Prefix
min :: Prefix -> Prefix -> Prefix
Ord, Int -> Prefix
Prefix -> Int
Prefix -> [Prefix]
Prefix -> Prefix
Prefix -> Prefix -> [Prefix]
Prefix -> Prefix -> Prefix -> [Prefix]
(Prefix -> Prefix)
-> (Prefix -> Prefix)
-> (Int -> Prefix)
-> (Prefix -> Int)
-> (Prefix -> [Prefix])
-> (Prefix -> Prefix -> [Prefix])
-> (Prefix -> Prefix -> [Prefix])
-> (Prefix -> Prefix -> Prefix -> [Prefix])
-> Enum Prefix
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Prefix -> Prefix
succ :: Prefix -> Prefix
$cpred :: Prefix -> Prefix
pred :: Prefix -> Prefix
$ctoEnum :: Int -> Prefix
toEnum :: Int -> Prefix
$cfromEnum :: Prefix -> Int
fromEnum :: Prefix -> Int
$cenumFrom :: Prefix -> [Prefix]
enumFrom :: Prefix -> [Prefix]
$cenumFromThen :: Prefix -> Prefix -> [Prefix]
enumFromThen :: Prefix -> Prefix -> [Prefix]
$cenumFromTo :: Prefix -> Prefix -> [Prefix]
enumFromTo :: Prefix -> Prefix -> [Prefix]
$cenumFromThenTo :: Prefix -> Prefix -> Prefix -> [Prefix]
enumFromThenTo :: Prefix -> Prefix -> Prefix -> [Prefix]
Enum, Prefix
Prefix -> Prefix -> Bounded Prefix
forall a. a -> a -> Bounded a
$cminBound :: Prefix
minBound :: Prefix
$cmaxBound :: Prefix
maxBound :: Prefix
Bounded, Int -> Prefix -> ShowS
[Prefix] -> ShowS
Prefix -> String
(Int -> Prefix -> ShowS)
-> (Prefix -> String) -> ([Prefix] -> ShowS) -> Show Prefix
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Prefix -> ShowS
showsPrec :: Int -> Prefix -> ShowS
$cshow :: Prefix -> String
show :: Prefix -> String
$cshowList :: [Prefix] -> ShowS
showList :: [Prefix] -> ShowS
Show)
data References = References { References -> Map Prefix RefMap
_stRefs :: M.Map Prefix RefMap
, References -> Map Prefix Index
_stCtrs :: M.Map Prefix Index
} deriving (Int -> References -> ShowS
[References] -> ShowS
References -> String
(Int -> References -> ShowS)
-> (References -> String)
-> ([References] -> ShowS)
-> Show References
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> References -> ShowS
showsPrec :: Int -> References -> ShowS
$cshow :: References -> String
show :: References -> String
$cshowList :: [References] -> ShowS
showList :: [References] -> ShowS
Show, References -> References -> Bool
(References -> References -> Bool)
-> (References -> References -> Bool) -> Eq References
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: References -> References -> Bool
== :: References -> References -> Bool
$c/= :: References -> References -> Bool
/= :: References -> References -> Bool
Eq)
instance Default References where
def :: References
def = Map Prefix RefMap -> Map Prefix Index -> References
References Map Prefix RefMap
forall a. Monoid a => a
mempty Map Prefix Index
forall a. Monoid a => a
mempty
makeLenses ''References
refsAt :: Prefix -> Lens' References RefMap
refsAt :: Prefix -> Lens' References RefMap
refsAt Prefix
pfx = (Map Prefix RefMap -> f (Map Prefix RefMap))
-> References -> f References
Lens' References (Map Prefix RefMap)
stRefs ((Map Prefix RefMap -> f (Map Prefix RefMap))
-> References -> f References)
-> ((RefMap -> f RefMap)
-> Map Prefix RefMap -> f (Map Prefix RefMap))
-> (RefMap -> f RefMap)
-> References
-> f References
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map Prefix RefMap)
-> Lens' (Map Prefix RefMap) (Maybe (IxValue (Map Prefix RefMap)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Index (Map Prefix RefMap)
Prefix
pfx ((Maybe RefMap -> f (Maybe RefMap))
-> Map Prefix RefMap -> f (Map Prefix RefMap))
-> ((RefMap -> f RefMap) -> Maybe RefMap -> f (Maybe RefMap))
-> (RefMap -> f RefMap)
-> Map Prefix RefMap
-> f (Map Prefix RefMap)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RefMap -> Lens' (Maybe RefMap) RefMap
forall a. Eq a => a -> Lens' (Maybe a) a
non RefMap
forall a. Monoid a => a
mempty
ctrsAt :: Prefix -> Lens' References Index
ctrsAt :: Prefix -> Lens' References Index
ctrsAt Prefix
pfx = (Map Prefix Index -> f (Map Prefix Index))
-> References -> f References
Lens' References (Map Prefix Index)
stCtrs ((Map Prefix Index -> f (Map Prefix Index))
-> References -> f References)
-> ((Index -> f Index) -> Map Prefix Index -> f (Map Prefix Index))
-> (Index -> f Index)
-> References
-> f References
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map Prefix Index)
-> Lens' (Map Prefix Index) (Maybe (IxValue (Map Prefix Index)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Index (Map Prefix Index)
Prefix
pfx ((Maybe Index -> f (Maybe Index))
-> Map Prefix Index -> f (Map Prefix Index))
-> ((Index -> f Index) -> Maybe Index -> f (Maybe Index))
-> (Index -> f Index)
-> Map Prefix Index
-> f (Map Prefix Index)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index -> Lens' (Maybe Index) Index
forall a. Eq a => a -> Lens' (Maybe a) a
non Index
forall a. Monoid a => a
mempty