]> Git — Sourcephile - doclang.git/blob - Language/DTC/Document.hs
Add DTC.Index.
[doclang.git] / Language / DTC / Document.hs
1 {-# LANGUAGE DisambiguateRecordFields #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
4 module Language.DTC.Document
5 ( module Language.DTC.Document
6 , module Language.XML
7 ) where
8
9 import Data.Default.Class (Default(..))
10 import Data.Eq (Eq)
11 import Data.Int (Int)
12 import Data.Maybe (Maybe(..))
13 import Data.Monoid (Monoid(..))
14 import Data.Semigroup (Semigroup(..))
15 import Data.Text (Text)
16 import Data.TreeSeq.Strict (Trees)
17 import Text.Show (Show)
18
19 import Language.XML
20
21 -- * Type 'Document'
22 data Document
23 = Document
24 { head :: Head
25 , body :: Body
26 } deriving (Eq,Show)
27 instance Default Document where
28 def = Document
29 { head = def
30 , body = mempty
31 }
32
33 -- * Type 'Head'
34 data Head
35 = Head
36 { about :: About
37 } deriving (Eq,Show)
38 instance Default Head where
39 def = Head
40 { about = def
41 }
42
43 -- ** Type 'About'
44 data About
45 = About
46 { titles :: [Title]
47 , authors :: [Entity]
48 , editor :: Maybe Entity
49 , date :: Maybe Date
50 , version :: MayText
51 , keywords :: [Text]
52 , links :: [Link]
53 , series :: [Serie]
54 , includes :: [Include]
55 } deriving (Eq,Show)
56 instance Default About where
57 def = About
58 { includes = def
59 , titles = def
60 , date = def
61 , version = def
62 , editor = def
63 , authors = def
64 , keywords = def
65 , links = def
66 , series = def
67 }
68 instance Semigroup About where
69 x <> y = About
70 { titles = titles x <> titles y
71 , authors = authors x <> authors y
72 , editor = editor x <> editor y
73 , date = date x <> date y
74 , version = version x <> version y
75 , keywords = keywords x <> keywords y
76 , links = links x <> links y
77 , series = series x <> series y
78 , includes = includes x <> includes y
79 }
80
81 -- * Type 'Body'
82 type Body = Trees BodyKey BodyValue
83
84 -- ** Type 'BodyKey'
85 data BodyKey
86 = Section { pos :: XmlPos
87 , attrs :: CommonAttrs
88 , title :: Title
89 , aliases :: [Alias]
90 }
91 deriving (Eq,Show)
92
93 -- ** Type 'BodyValue'
94 data BodyValue
95 = ToC { pos :: XmlPos
96 , attrs :: CommonAttrs
97 , depth :: Maybe Nat
98 }
99 | ToF { pos :: XmlPos
100 , attrs :: CommonAttrs
101 , depth :: Maybe Nat
102 }
103 | Figure { pos :: XmlPos
104 , attrs :: CommonAttrs
105 , type_ :: Text
106 , title :: Title
107 , verts :: Verticals
108 }
109 | Index { pos :: XmlPos
110 , attrs :: CommonAttrs
111 , terms :: [[Text]]
112 }
113 | Vertical Vertical
114 deriving (Eq,Show)
115
116 -- * Type 'Vertical'
117 data Vertical
118 = Para { pos :: XmlPos
119 , attrs :: CommonAttrs
120 , horis :: Horizontals
121 }
122 | OL { pos :: XmlPos
123 , attrs :: CommonAttrs
124 , items :: [Verticals]
125 }
126 | UL { pos :: XmlPos
127 , attrs :: CommonAttrs
128 , items :: [Verticals]
129 }
130 | RL { pos :: XmlPos
131 , attrs :: CommonAttrs
132 , refs :: [Reference]
133 }
134 | Artwork { pos :: XmlPos
135 , attrs :: CommonAttrs
136 , art :: Artwork
137 }
138 | Comment Text
139 deriving (Eq,Show)
140
141 -- * Type 'CommonAttrs'
142 data CommonAttrs
143 = CommonAttrs
144 { id :: Maybe Ident
145 , classes :: [Text]
146 } deriving (Eq,Show)
147
148 -- * Type 'Auto'
149 data Auto
150 = Auto
151 { auto_id :: Ident
152 } deriving (Eq,Show)
153
154 -- * Type 'Verticals'
155 type Verticals = [Vertical]
156
157 -- * Type 'Artwork'
158 data Artwork
159 = Raw Text
160 deriving (Eq,Show)
161
162 -- * Type 'Horizontal'
163 data Horizontal
164 = BR
165 | B Horizontals
166 | Code Horizontals
167 | Del Horizontals
168 | I Horizontals
169 | Note Horizontals
170 | Q Horizontals
171 | SC Horizontals
172 | Sub Horizontals
173 | Sup Horizontals
174 | U Horizontals
175 | Eref {href :: URL, text :: Horizontals}
176 | Iref {count :: Int, term :: Text, text :: Horizontals}
177 | Ref {to :: Ident, text :: Horizontals}
178 | Rref {to :: Ident, text :: Horizontals}
179 | Plain Text
180 deriving (Eq,Show)
181
182 -- * Type 'Horizontals'
183 type Horizontals = [Horizontal]
184
185 -- * Type 'Title'
186 newtype Title = Title { unTitle :: Horizontals }
187 deriving (Eq,Show,Default)
188
189 -- ** Type 'Address'
190 data Address
191 = Address
192 { street :: Text
193 , zipcode :: Text
194 , city :: Text
195 , region :: Text
196 , country :: Text
197 , email :: Text
198 , tel :: Text
199 , fax :: Text
200 } deriving (Eq,Show)
201 instance Default Address where
202 def = Address
203 { street = def
204 , zipcode = def
205 , city = def
206 , region = def
207 , country = def
208 , email = def
209 , tel = def
210 , fax = def
211 }
212
213 -- * Type 'Include'
214 data Include
215 = Include
216 { href :: Path
217 } deriving (Eq,Show)
218 instance Default Include where
219 def = Include
220 { href = def
221 }
222
223 -- * Type 'Reference'
224 data Reference
225 = Reference
226 { id :: Ident
227 , to :: Maybe URL
228 , about :: About
229 } deriving (Eq,Show)
230 reference :: Ident -> Reference
231 reference id =
232 Reference
233 { id
234 , to = def
235 , about = def
236 }
237 instance Default Reference where
238 def = reference def
239
240 -- * Type 'Entity'
241 data Entity
242 = Entity
243 { name :: Text
244 , address :: Address
245 } deriving (Eq,Show)
246 instance Default Entity where
247 def = Entity
248 { name = def
249 , address = def
250 }
251 instance Semigroup Entity where
252 _x <> y = y
253
254 -- * Type 'Date'
255 data Date
256 = Date
257 { year :: Int
258 , month :: Maybe Nat1
259 , day :: Maybe Nat1
260 } deriving (Eq,Show)
261 instance Default Date where
262 def = Date
263 { year = 1970
264 , month = Just (Nat1 01)
265 , day = Just (Nat1 01)
266 }
267 instance Semigroup Date where
268 _x <> y = y
269
270 -- * Type 'Link'
271 data Link
272 = Link
273 { name :: Text
274 , href :: URL
275 , rel :: Text
276 , body :: Horizontals
277 } deriving (Eq,Show)
278 instance Default Link where
279 def = Link
280 { name = def
281 , href = def
282 , rel = def
283 , body = def
284 }
285
286 -- * Type 'Alias'
287 data Alias
288 = Alias
289 { id :: Ident
290 } deriving (Eq,Show)
291 instance Default Alias where
292 def = Alias
293 { id = def
294 }
295
296 -- * Type 'Serie'
297 data Serie
298 = Serie
299 { name :: Text
300 , key :: Text
301 } deriving (Eq,Show)
302 instance Default Serie where
303 def = Serie
304 { name = def
305 , key = def
306 }