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