1 {-# LANGUAGE NoMonomorphismRestriction #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 module Language.DTC.Sym where
5 import Control.Applicative (Applicative(..), (<$>), (<$))
6 import Control.Monad (void)
7 import Data.Default.Class (Default(..))
8 import Data.Foldable (Foldable(..))
9 import Data.Function (($), flip)
10 import Data.Maybe (Maybe(..), maybe)
11 import Data.Text (Text)
12 import Data.TreeSeq.Strict (Tree(..))
13 import qualified Data.Sequence as Seq
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 document :: repr DTC.Document
30 about :: repr DTC.About
32 version :: repr MayText
33 author :: repr DTC.Entity
34 editor :: repr DTC.Entity
36 entity :: repr DTC.Entity
37 address :: repr DTC.Address
39 serie :: repr DTC.Serie
40 alias :: repr DTC.Alias
43 bodyKey :: repr DTC.BodyKey
44 bodyValue :: repr DTC.BodyValue
45 toc :: repr DTC.BodyValue
46 tof :: repr DTC.BodyValue
47 index :: repr DTC.BodyValue
48 figure :: repr DTC.BodyValue
49 reference :: repr DTC.Reference
50 include :: repr DTC.Include
52 vertical :: repr DTC.Vertical
53 horizontals :: repr DTC.Horizontals
54 horizontal :: repr DTC.Horizontal
56 commonAttrs :: repr DTC.CommonAttrs
58 title :: repr DTC.Title
69 <$?> (def, Just <$> id)
70 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
72 document = rule "document" $
78 <$> optional (rule "about" $ element "about" about)
84 [ rule "section" $ element "section" $ TreeN <$> bodyKey <*> body
99 , DTC.Vertical <$> vertical
101 title = rule "title" $ DTC.Title <$> element "title" horizontals
102 name = rule "name" $ attribute "name" text
103 url = rule "url" $ URL <$> text
104 path = rule "path" $ Path <$> text
105 ident = rule "ident" $ Ident <$> text
106 to = rule "to" $ attribute "to" ident
107 id = rule "id" $ attribute "id" ident
112 <$?> (0, attribute "year" int)
113 <|?> (Nothing, Just <$> attribute "month" nat1)
114 <|?> (Nothing, Just <$> attribute "day" nat1)
115 include = rule "include" $
119 <$?> (def, attribute "href" path)
120 vertical = rule "vertical" $
122 [ DTC.Comment <$> comment
132 <*> many (element "li" $ many vertical)
137 <*> many (element "li" $ many vertical)
144 , anyElem $ \n@XmlName{..} ->
155 <*> optional (attribute "depth" nat)
162 <*> optional (attribute "depth" nat)
181 <*> attribute "type" text
184 horizontals = many horizontal
185 horizontal = rule "horizontal" $
187 [ DTC.BR <$ element "br" none
188 , DTC.B <$> element "b" horizontals
189 , DTC.Code <$> element "code" horizontals
190 , DTC.Del <$> element "del" horizontals
191 , DTC.I <$> element "i" horizontals
192 , DTC.Note <$> element "note" horizontals
193 , DTC.Q <$> element "q" horizontals
194 , DTC.SC <$> element "sc" horizontals
195 , DTC.Sub <$> element "sub" horizontals
196 , DTC.Sup <$> element "sup" horizontals
197 , DTC.U <$> element "u" horizontals
198 , element "eref" $ DTC.Eref
199 <$> attribute "to" url
201 , element "iref" $ DTC.Iref 0 <$> text <*> horizontals
202 , element "ref" $ DTC.Ref <$> to <*> horizontals
203 , element "rref" $ DTC.Rref <$> to <*> horizontals
206 keyword = rule "keyword" $
207 element "keyword" text
208 version = rule "version" $
210 element "version" text
216 <|?> (Nothing, Just <$> editor)
217 <|?> (Nothing, Just <$> date)
223 author = rule "author" $ element "author" entity
224 editor = rule "editor" $ element "editor" entity
225 entity = rule "entity" $
229 address = rule "address" $
233 <$?> (def, attribute "street" text)
234 <|?> (def, attribute "zipcode" text)
235 <|?> (def, attribute "city" text)
236 <|?> (def, attribute "region" text)
237 <|?> (def, attribute "country" text)
238 <|?> (def, attribute "email" text)
239 <|?> (def, attribute "tel" text)
240 <|?> (def, attribute "fax" text)
241 serie = rule "serie" $
245 <$?> (def, attribute "name" text)
246 <|?> (def, attribute "key" text)
251 <$?> (def, attribute "name" text)
252 <|?> (def, attribute "href" url)
253 <|?> (def, attribute "rel" text)
255 alias = rule "alias" $
260 reference = rule "reference" $
261 element "reference" $
264 <*> optional (attribute "to" url)
267 instance Sym_DTC RNC.Writer
268 instance Sym_DTC RNC.RuleWriter
269 dtcRNC :: [RNC.RuleWriter ()]
274 , void $ rule "about" $ element "about" about
297 , void $ rule "horizontals" horizontals