1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
8 import Data.Default.Class (Default(..))
9 import Data.Eq (Eq(..))
10 import Data.Function ((.), on)
11 import Data.Hashable (Hashable(..))
12 import Data.Map.Strict (Map)
13 import Data.Maybe (Maybe(..))
14 import Data.Monoid (Monoid(..))
15 import Data.Ord (Ord(..))
16 import Data.Semigroup (Semigroup(..))
17 import Data.Sequence (Seq)
18 import Data.String (IsString(..))
19 import Text.Show (Show(..), showsPrec)
20 import qualified Data.Sequence as Seq
21 import qualified Data.Text.Lazy as TL
22 import qualified Language.Symantic.XML as XML
24 import qualified Hdoc.TCT.Cell as TCT
25 import Hdoc.Utils (Nat1)
28 type XML = XML.XML TCT.Location
30 type XMLs = XML.XMLs TCT.Location
33 type Attrs = Map XML.QName (TCT.Cell TL.Text)
34 -- TODO: Map -> HashMap?
38 { pos_ancestors :: Ancestors
39 , pos_ancestorsWithFigureNames :: Ancestors
40 , pos_precedingSiblings :: Map XML.QName Rank
42 instance Ord Pos where
43 compare = compare`on`pos_ancestors
44 -- | Return only the hash on 'pos_ancestors',
45 -- which is unique because 'Ancestors'
46 -- includes the 'Rank' of each 'Node'.
47 instance Hashable Pos where
48 hashWithSalt s Pos{..} =
49 s`hashWithSalt`pos_ancestors
50 instance Default Pos where
51 def = Pos mempty mempty mempty
57 -- ** Type 'Ancestors'
58 type Ancestors = Seq (XML.QName, Rank)
60 ancestors :: Ancestors -> Maybe Ancestors
64 ls Seq.:> _ -> Just ls
67 newtype Ident = Ident { unIdent :: TL.Text }
68 deriving (Eq,Ord,Show,Default,IsString,Semigroup,Monoid,Hashable)
71 newtype URL = URL { unURL :: TL.Text }
72 deriving (Eq,Ord,Default,Hashable)
73 instance Show URL where
74 showsPrec p = showsPrec p . unURL
75 instance Semigroup URL where