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 qualified Data.Text as Text
17 import Language.RNC.Sym as RNC
18 import qualified Language.DTC.Document as DTC
19 import qualified Language.RNC.Write as RNC
21 foldlApp :: (Default a, Foldable t) => t (a -> a) -> a
22 foldlApp = foldl' (flip ($)) def
23 foldrApp :: (Default a, Foldable t) => t (a -> a) -> a
24 foldrApp = foldr ($) def
26 class RNC.Sym_RNC repr => Sym_DTC repr where
27 title :: repr DTC.Title
35 include :: repr DTC.Include
36 horizontals :: repr DTC.Horizontals
37 horizontal :: repr DTC.Horizontal
38 vertical :: repr DTC.Vertical
39 reference :: repr DTC.Reference
40 document :: repr DTC.Document
42 body :: repr [DTC.Body]
43 about :: repr DTC.About
45 version :: repr MayText
46 author :: repr DTC.Entity
47 editor :: repr DTC.Entity
48 entity :: repr DTC.Entity
49 address :: repr DTC.Address
51 serie :: repr DTC.Serie
52 alias :: repr DTC.Alias
53 figure :: repr DTC.Vertical
54 commonAttrs :: repr DTC.CommonAttrs
59 <$?> (def, Just <$> id)
60 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
62 document = rule "document" $
68 <$> optional (rule "about" $ element "about" about)
85 <*> optional (attribute "depth" nat)
90 <*> optional (attribute "depth" nat)
99 title = rule "title" $ DTC.Title <$> element "title" horizontals
100 name = rule "name" $ attribute "name" text
101 url = rule "url" $ URL <$> text
102 path = rule "path" $ Path <$> text
103 ident = rule "ident" $ Ident <$> text
104 to = rule "to" $ attribute "to" ident
105 id = rule "id" $ attribute "id" ident
110 <$?> (0, attribute "year" int)
111 <|?> (Nothing, Just <$> attribute "month" nat1)
112 <|?> (Nothing, Just <$> attribute "day" nat1)
113 include = rule "include" $
117 <$?> (def, attribute "href" path)
118 vertical = rule "vertical" $
120 [ DTC.Comment <$> comment
130 <*> many (element "li" $ many vertical)
135 <*> many (element "li" $ many vertical)
143 , anyElem $ \n@XmlName{..} ->
153 <$> attribute "type" text
157 horizontals = many horizontal
158 horizontal = rule "horizontal" $
160 [ DTC.BR <$ element "br" none
161 , DTC.B <$> element "b" horizontals
162 , DTC.Code <$> element "code" horizontals
163 , DTC.Del <$> element "del" horizontals
164 , DTC.I <$> element "i" horizontals
165 , DTC.Note <$> element "note" horizontals
166 , DTC.Q <$> element "q" horizontals
167 , DTC.SC <$> element "sc" horizontals
168 , DTC.Sub <$> element "sub" horizontals
169 , DTC.Sup <$> element "sup" horizontals
170 , DTC.U <$> element "u" horizontals
171 , element "eref" $ DTC.Eref
172 <$> attribute "to" url
174 , element "iref" $ DTC.Iref <$> to <*> horizontals
175 , element "ref" $ DTC.Ref <$> to <*> horizontals
176 , element "rref" $ DTC.Rref <$> to <*> horizontals
179 keyword = rule "keyword" $
180 element "keyword" text
181 version = rule "version" $
183 element "version" text
189 <|?> (Nothing, Just <$> editor)
190 <|?> (Nothing, Just <$> date)
196 author = rule "author" $ element "author" entity
197 editor = rule "editor" $ element "editor" entity
198 entity = rule "entity" $
202 address = rule "address" $
206 <$?> (def, attribute "street" text)
207 <|?> (def, attribute "zipcode" text)
208 <|?> (def, attribute "city" text)
209 <|?> (def, attribute "region" text)
210 <|?> (def, attribute "country" text)
211 <|?> (def, attribute "email" text)
212 <|?> (def, attribute "tel" text)
213 <|?> (def, attribute "fax" text)
214 serie = rule "serie" $
218 <$?> (def, attribute "name" text)
219 <|?> (def, attribute "key" text)
224 <$?> (def, attribute "name" text)
225 <|?> (def, attribute "href" url)
226 <|?> (def, attribute "rel" text)
228 alias = rule "alias" $
233 reference = rule "reference" $
234 element "reference" $
237 <*> optional (attribute "to" url)
240 instance Sym_DTC RNC.Writer
241 instance Sym_DTC RNC.RuleWriter
242 dtcRNC :: [RNC.RuleWriter ()]
250 , void $ rule "horizontals" horizontals
262 , void $ rule "about" $ element "about" about