1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
5 import Data.Default.Class (Default(..))
6 import Data.Eq (Eq(..))
7 import Data.Function ((.), on)
8 import Data.Hashable (Hashable(..))
9 import Data.Map.Strict (Map)
10 import Data.Maybe (Maybe(..))
11 import Data.Monoid (Monoid(..))
12 import Data.Ord (Ord(..))
13 import Data.Semigroup (Semigroup(..))
14 import Data.Sequence (Seq)
15 import Data.String (IsString(..))
16 import Text.Show (Show(..), showsPrec)
17 import qualified Data.Sequence as Seq
18 import qualified Data.Text.Lazy as TL
19 import qualified Language.Symantic.XML as XML
21 import qualified Hdoc.TCT.Cell as TCT
22 import Hdoc.Utils (Nat1)
26 type Attrs = Map XML.QName (TCT.Cell TL.Text)
27 -- TODO: Map -> HashMap?
31 { pos_ancestors :: Ancestors
32 , pos_ancestorsWithFigureNames :: Ancestors
33 , pos_precedingSiblings :: Map XML.QName Rank
35 instance Ord Pos where
36 compare = compare`on`pos_ancestors
37 -- | Return only the hash on 'pos_ancestors',
38 -- which is unique because 'Ancestors'
39 -- includes the 'Rank' of each 'Node'.
40 instance Hashable Pos where
41 hashWithSalt s Pos{..} =
42 s`hashWithSalt`pos_ancestors
43 instance Default Pos where
44 def = Pos mempty mempty mempty
50 -- ** Type 'Ancestors'
51 type Ancestors = Seq (XML.QName, Rank)
53 ancestors :: Ancestors -> Maybe Ancestors
57 ls Seq.:> _ -> Just ls
60 newtype Ident = Ident { unIdent :: TL.Text }
61 deriving (Eq,Ord,Show,Default,IsString,Semigroup,Monoid,Hashable)
64 newtype URL = URL { unURL :: TL.Text }
65 deriving (Eq,Ord,Default,Hashable)
66 instance Show URL where
67 showsPrec p = showsPrec p . unURL
68 instance Semigroup URL where