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, foldl', foldr)
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 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
43 bodyKey :: repr DTC.BodyKey
44 bodyValue :: repr DTC.BodyValue
45 figure :: repr DTC.BodyValue
46 about :: repr DTC.About
48 version :: repr MayText
49 author :: repr DTC.Entity
50 editor :: repr DTC.Entity
51 entity :: repr DTC.Entity
52 address :: repr DTC.Address
54 serie :: repr DTC.Serie
55 alias :: repr DTC.Alias
56 commonAttrs :: repr DTC.CommonAttrs
61 <$?> (def, Just <$> id)
62 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
64 document = rule "document" $
70 <$> optional (rule "about" $ element "about" about)
76 [ rule "section" $ element "section" $ TreeN <$> bodyKey <*> body
77 , Tree0 . Seq.fromList <$> some bodyValue
91 <*> optional (attribute "depth" nat)
96 <*> optional (attribute "depth" nat)
106 title = rule "title" $ DTC.Title <$> element "title" horizontals
107 name = rule "name" $ attribute "name" text
108 url = rule "url" $ URL <$> text
109 path = rule "path" $ Path <$> text
110 ident = rule "ident" $ Ident <$> text
111 to = rule "to" $ attribute "to" ident
112 id = rule "id" $ attribute "id" ident
117 <$?> (0, attribute "year" int)
118 <|?> (Nothing, Just <$> attribute "month" nat1)
119 <|?> (Nothing, Just <$> attribute "day" nat1)
120 include = rule "include" $
124 <$?> (def, attribute "href" path)
125 vertical = rule "vertical" $
127 [ DTC.Comment <$> comment
137 <*> many (element "li" $ many vertical)
142 <*> many (element "li" $ many vertical)
149 , anyElem $ \n@XmlName{..} ->
159 <$> attribute "type" text
163 horizontals = many horizontal
164 horizontal = rule "horizontal" $
166 [ DTC.BR <$ element "br" none
167 , DTC.B <$> element "b" horizontals
168 , DTC.Code <$> element "code" horizontals
169 , DTC.Del <$> element "del" horizontals
170 , DTC.I <$> element "i" horizontals
171 , DTC.Note <$> element "note" horizontals
172 , DTC.Q <$> element "q" horizontals
173 , DTC.SC <$> element "sc" horizontals
174 , DTC.Sub <$> element "sub" horizontals
175 , DTC.Sup <$> element "sup" horizontals
176 , DTC.U <$> element "u" horizontals
177 , element "eref" $ DTC.Eref
178 <$> attribute "to" url
180 , element "iref" $ DTC.Iref <$> to <*> horizontals
181 , element "ref" $ DTC.Ref <$> to <*> horizontals
182 , element "rref" $ DTC.Rref <$> to <*> horizontals
185 keyword = rule "keyword" $
186 element "keyword" text
187 version = rule "version" $
189 element "version" text
195 <|?> (Nothing, Just <$> editor)
196 <|?> (Nothing, Just <$> date)
202 author = rule "author" $ element "author" entity
203 editor = rule "editor" $ element "editor" entity
204 entity = rule "entity" $
208 address = rule "address" $
212 <$?> (def, attribute "street" text)
213 <|?> (def, attribute "zipcode" text)
214 <|?> (def, attribute "city" text)
215 <|?> (def, attribute "region" text)
216 <|?> (def, attribute "country" text)
217 <|?> (def, attribute "email" text)
218 <|?> (def, attribute "tel" text)
219 <|?> (def, attribute "fax" text)
220 serie = rule "serie" $
224 <$?> (def, attribute "name" text)
225 <|?> (def, attribute "key" text)
230 <$?> (def, attribute "name" text)
231 <|?> (def, attribute "href" url)
232 <|?> (def, attribute "rel" text)
234 alias = rule "alias" $
239 reference = rule "reference" $
240 element "reference" $
243 <*> optional (attribute "to" url)
246 instance Sym_DTC RNC.Writer
247 instance Sym_DTC RNC.RuleWriter
248 dtcRNC :: [RNC.RuleWriter ()]
256 , void $ rule "horizontals" horizontals
268 , void $ rule "about" $ element "about" about