1 {-# LANGUAGE NamedFieldPuns #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
3 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE RecordWildCards #-}
5 module Language.DTC.Sym where
7 import Control.Applicative (Applicative(..), (<$>), (<$))
8 import Control.Monad (void)
9 import Data.Default.Class (Default(..))
10 import Data.Foldable (Foldable, foldl', foldr)
11 import Data.Function (($), (.), flip)
12 import Data.Maybe (Maybe(..), maybe)
13 import Data.Text (Text)
14 import Data.TreeSeq.Strict (Tree(..))
15 import qualified Data.Sequence as Seq
16 import qualified Data.Text as Text
19 import Language.RNC.Sym as RNC
20 import qualified Language.DTC.Document as DTC
21 import qualified Language.RNC.Write as RNC
23 foldlApp :: (Default a, Foldable t) => t (a -> a) -> a
24 foldlApp = foldl' (flip ($)) def
25 foldrApp :: (Default a, Foldable t) => t (a -> a) -> a
26 foldrApp = foldr ($) def
28 class RNC.Sym_RNC repr => Sym_DTC repr where
29 title :: repr DTC.Title
37 include :: repr DTC.Include
38 horizontals :: repr DTC.Horizontals
39 horizontal :: repr DTC.Horizontal
40 vertical :: repr DTC.Vertical
41 reference :: repr DTC.Reference
42 document :: repr DTC.Document
45 bodyKey :: repr DTC.BodyKey
46 bodyValue :: repr DTC.BodyValue
47 figure :: repr DTC.BodyValue
48 about :: repr DTC.About
50 version :: repr MayText
51 author :: repr DTC.Entity
52 editor :: repr DTC.Entity
53 entity :: repr DTC.Entity
54 address :: repr DTC.Address
56 serie :: repr DTC.Serie
57 alias :: repr DTC.Alias
58 commonAttrs :: repr DTC.CommonAttrs
63 <$?> (def, Just <$> id)
64 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
66 document = rule "document" $
72 <$> optional (rule "about" $ element "about" about)
78 [ rule "section" $ element "section" $ TreeN <$> bodyKey <*> body
79 , Tree0 . Seq.fromList <$> some bodyValue
93 <*> optional (attribute "depth" nat)
98 <*> optional (attribute "depth" nat)
108 title = rule "title" $ DTC.Title <$> element "title" horizontals
109 name = rule "name" $ attribute "name" text
110 url = rule "url" $ URL <$> text
111 path = rule "path" $ Path <$> text
112 ident = rule "ident" $ Ident <$> text
113 to = rule "to" $ attribute "to" ident
114 id = rule "id" $ attribute "id" ident
119 <$?> (0, attribute "year" int)
120 <|?> (Nothing, Just <$> attribute "month" nat1)
121 <|?> (Nothing, Just <$> attribute "day" nat1)
122 include = rule "include" $
126 <$?> (def, attribute "href" path)
127 vertical = rule "vertical" $
129 [ DTC.Comment <$> comment
139 <*> many (element "li" $ many vertical)
144 <*> many (element "li" $ many vertical)
151 , anyElem $ \n@XmlName{..} ->
161 <$> attribute "type" text
165 horizontals = many horizontal
166 horizontal = rule "horizontal" $
168 [ DTC.BR <$ element "br" none
169 , DTC.B <$> element "b" horizontals
170 , DTC.Code <$> element "code" horizontals
171 , DTC.Del <$> element "del" horizontals
172 , DTC.I <$> element "i" horizontals
173 , DTC.Note <$> element "note" horizontals
174 , DTC.Q <$> element "q" horizontals
175 , DTC.SC <$> element "sc" horizontals
176 , DTC.Sub <$> element "sub" horizontals
177 , DTC.Sup <$> element "sup" horizontals
178 , DTC.U <$> element "u" horizontals
179 , element "eref" $ DTC.Eref
180 <$> attribute "to" url
182 , element "iref" $ DTC.Iref <$> to <*> horizontals
183 , element "ref" $ DTC.Ref <$> to <*> horizontals
184 , element "rref" $ DTC.Rref <$> to <*> horizontals
187 keyword = rule "keyword" $
188 element "keyword" text
189 version = rule "version" $
191 element "version" text
197 <|?> (Nothing, Just <$> editor)
198 <|?> (Nothing, Just <$> date)
204 author = rule "author" $ element "author" entity
205 editor = rule "editor" $ element "editor" entity
206 entity = rule "entity" $
210 address = rule "address" $
214 <$?> (def, attribute "street" text)
215 <|?> (def, attribute "zipcode" text)
216 <|?> (def, attribute "city" text)
217 <|?> (def, attribute "region" text)
218 <|?> (def, attribute "country" text)
219 <|?> (def, attribute "email" text)
220 <|?> (def, attribute "tel" text)
221 <|?> (def, attribute "fax" text)
222 serie = rule "serie" $
226 <$?> (def, attribute "name" text)
227 <|?> (def, attribute "key" text)
232 <$?> (def, attribute "name" text)
233 <|?> (def, attribute "href" url)
234 <|?> (def, attribute "rel" text)
236 alias = rule "alias" $
241 reference = rule "reference" $
242 element "reference" $
245 <*> optional (attribute "to" url)
248 instance Sym_DTC RNC.Writer
249 instance Sym_DTC RNC.RuleWriter
250 dtcRNC :: [RNC.RuleWriter ()]
258 , void $ rule "horizontals" horizontals
270 , void $ rule "about" $ element "about" about