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 Language.DTC.Index (wordify)
19 import qualified Language.DTC.Document as DTC
20 import qualified Language.RNC.Write as RNC
22 foldlApp :: (Default a, Foldable t) => t (a -> a) -> a
23 foldlApp = foldl' (flip ($)) def
24 foldrApp :: (Default a, Foldable t) => t (a -> a) -> a
25 foldrApp = foldr ($) def
27 class RNC.Sym_RNC repr => Sym_DTC repr where
28 document :: repr DTC.Document
31 about :: repr DTC.About
33 version :: repr MayText
34 author :: repr DTC.Entity
35 editor :: repr DTC.Entity
37 entity :: repr DTC.Entity
38 address :: repr DTC.Address
40 serie :: repr DTC.Serie
41 alias :: repr DTC.Alias
44 bodyKey :: repr DTC.BodyKey
45 bodyValue :: repr DTC.BodyValue
46 toc :: repr DTC.BodyValue
47 tof :: repr DTC.BodyValue
48 index :: repr DTC.BodyValue
49 figure :: repr DTC.BodyValue
50 reference :: repr DTC.Reference
51 include :: repr DTC.Include
53 vertical :: repr DTC.Vertical
54 horizontals :: repr DTC.Horizontals
55 horizontal :: repr DTC.Horizontal
57 commonAttrs :: repr DTC.CommonAttrs
59 title :: repr DTC.Title
70 <$?> (def, Just <$> id)
71 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
73 document = rule "document" $
79 <$> optional (rule "about" $ element "about" about)
85 [ rule "section" $ element "section" $ TreeN <$> bodyKey <*> body
100 , DTC.Vertical <$> vertical
102 title = rule "title" $ DTC.Title <$> element "title" horizontals
103 name = rule "name" $ attribute "name" text
104 url = rule "url" $ URL <$> text
105 path = rule "path" $ Path <$> text
106 ident = rule "ident" $ Ident <$> text
107 to = rule "to" $ attribute "to" ident
108 id = rule "id" $ attribute "id" ident
113 <$?> (0, attribute "year" int)
114 <|?> (Nothing, Just <$> attribute "month" nat1)
115 <|?> (Nothing, Just <$> attribute "day" nat1)
116 include = rule "include" $
120 <$?> (def, attribute "href" path)
121 vertical = rule "vertical" $
123 [ DTC.Comment <$> comment
133 <*> many (element "li" $ many vertical)
138 <*> many (element "li" $ many vertical)
145 , anyElem $ \n@XmlName{..} ->
156 <*> optional (attribute "depth" nat)
163 <*> optional (attribute "depth" nat)
176 (wordify <$>) . Text.lines <$> text)
183 <*> attribute "type" text
186 horizontals = many horizontal
187 horizontal = rule "horizontal" $
189 [ DTC.BR <$ element "br" none
190 , DTC.B <$> element "b" horizontals
191 , DTC.Code <$> element "code" horizontals
192 , DTC.Del <$> element "del" horizontals
193 , DTC.I <$> element "i" horizontals
194 , DTC.Note <$> element "note" horizontals
195 , DTC.Q <$> element "q" horizontals
196 , DTC.SC <$> element "sc" horizontals
197 , DTC.Sub <$> element "sub" horizontals
198 , DTC.Sup <$> element "sup" horizontals
199 , DTC.U <$> element "u" horizontals
200 , element "eref" $ DTC.Eref
201 <$> attribute "to" url
203 , element "iref" $ DTC.Iref 0 . wordify <$> text <*> horizontals
204 , element "ref" $ DTC.Ref <$> to <*> horizontals
205 , element "rref" $ DTC.Rref <$> to <*> horizontals
208 keyword = rule "keyword" $
209 element "keyword" text
210 version = rule "version" $
212 element "version" text
218 <|?> (Nothing, Just <$> editor)
219 <|?> (Nothing, Just <$> date)
225 author = rule "author" $ element "author" entity
226 editor = rule "editor" $ element "editor" entity
227 entity = rule "entity" $
231 address = rule "address" $
235 <$?> (def, attribute "street" text)
236 <|?> (def, attribute "zipcode" text)
237 <|?> (def, attribute "city" text)
238 <|?> (def, attribute "region" text)
239 <|?> (def, attribute "country" text)
240 <|?> (def, attribute "email" text)
241 <|?> (def, attribute "tel" text)
242 <|?> (def, attribute "fax" text)
243 serie = rule "serie" $
247 <$?> (def, attribute "name" text)
248 <|?> (def, attribute "key" text)
253 <$?> (def, attribute "name" text)
254 <|?> (def, attribute "href" url)
255 <|?> (def, attribute "rel" text)
257 alias = rule "alias" $
262 reference = rule "reference" $
263 element "reference" $
266 <*> optional (attribute "to" url)
269 instance Sym_DTC RNC.Writer
270 instance Sym_DTC RNC.RuleWriter
271 dtcRNC :: [RNC.RuleWriter ()]
276 , void $ rule "about" $ element "about" about
299 , void $ rule "horizontals" horizontals