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(..), concat)
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)
173 element "para" (many text)
182 <*> attribute "type" text
185 horizontals = many horizontal
186 horizontal = rule "horizontal" $
188 [ DTC.BR <$ element "br" none
189 , DTC.B <$> element "b" horizontals
190 , DTC.Code <$> element "code" horizontals
191 , DTC.Del <$> element "del" horizontals
192 , DTC.I <$> element "i" horizontals
193 , DTC.Note <$> element "note" horizontals
194 , DTC.Q <$> element "q" horizontals
195 , DTC.SC <$> element "sc" horizontals
196 , DTC.Sub <$> element "sub" horizontals
197 , DTC.Sup <$> element "sup" horizontals
198 , DTC.U <$> element "u" horizontals
199 , element "eref" $ DTC.Eref
200 <$> attribute "to" url
202 , element "iref" $ DTC.Iref 0 <$> text <*> horizontals
203 , element "ref" $ DTC.Ref <$> to <*> horizontals
204 , element "rref" $ DTC.Rref <$> to <*> horizontals
207 keyword = rule "keyword" $
208 element "keyword" text
209 version = rule "version" $
211 element "version" text
217 <|?> (Nothing, Just <$> editor)
218 <|?> (Nothing, Just <$> date)
224 author = rule "author" $ element "author" entity
225 editor = rule "editor" $ element "editor" entity
226 entity = rule "entity" $
230 address = rule "address" $
234 <$?> (def, attribute "street" text)
235 <|?> (def, attribute "zipcode" text)
236 <|?> (def, attribute "city" text)
237 <|?> (def, attribute "region" text)
238 <|?> (def, attribute "country" text)
239 <|?> (def, attribute "email" text)
240 <|?> (def, attribute "tel" text)
241 <|?> (def, attribute "fax" text)
242 serie = rule "serie" $
246 <$?> (def, attribute "name" text)
247 <|?> (def, attribute "key" text)
252 <$?> (def, attribute "name" text)
253 <|?> (def, attribute "href" url)
254 <|?> (def, attribute "rel" text)
256 alias = rule "alias" $
261 reference = rule "reference" $
262 element "reference" $
265 <*> optional (attribute "to" url)
268 instance Sym_DTC RNC.Writer
269 instance Sym_DTC RNC.RuleWriter
270 dtcRNC :: [RNC.RuleWriter ()]
275 , void $ rule "about" $ element "about" about
298 , void $ rule "horizontals" horizontals