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.Foldable (Foldable, foldl', foldr)
10 import Data.Function (($), flip)
11 import Data.Maybe (Maybe(..), maybe)
12 import Data.Text (Text)
13 import qualified Data.Text as Text
15 import Language.DTC.Document (Default(..), MayText(..))
16 import Language.RNC.Sym as RNC
17 import qualified Language.DTC.Document as DTC
18 import qualified Language.RNC.Write as RNC
20 foldlApp :: (DTC.Default a, Foldable t) => t (a -> a) -> a
21 foldlApp = foldl' (flip ($)) def
22 foldrApp :: (DTC.Default a, Foldable t) => t (a -> a) -> a
23 foldrApp = foldr ($) def
25 class RNC.Sym_RNC repr => Sym_DTC repr where
26 title :: repr DTC.Title
30 ident :: repr DTC.Ident
34 include :: repr DTC.Include
35 horizontals :: repr DTC.Horizontals
36 horizontal :: repr DTC.Horizontal
37 vertical :: repr DTC.Vertical
38 reference :: repr DTC.Reference
39 document :: repr DTC.Document
41 body :: repr [DTC.Body]
42 about :: repr DTC.About
44 version :: repr MayText
45 author :: repr DTC.Entity
46 editor :: repr DTC.Entity
47 entity :: repr DTC.Entity
48 address :: repr DTC.Address
50 serie :: repr DTC.Serie
51 alias :: repr DTC.Alias
52 figure :: repr DTC.Vertical
53 commonAttrs :: repr DTC.CommonAttrs
58 <$?> (def, Just <$> id)
59 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
61 document = rule "document" $
67 <$> optional (rule "about" $ element "about" about)
82 title = rule "title" $ DTC.Title <$> element "title" horizontals
83 name = rule "name" $ attribute "name" text
84 url = rule "url" $ DTC.URL <$> text
85 path = rule "path" $ DTC.Path <$> text
86 ident = rule "ident" $ DTC.Ident <$> text
87 to = rule "to" $ attribute "to" ident
88 id = rule "id" $ attribute "id" ident
93 <$?> (0, attribute "year" int)
94 <|?> (Nothing, Just <$> attribute "month" nat1)
95 <|?> (Nothing, Just <$> attribute "day" nat1)
96 include = rule "include" $
100 <$?> (def, attribute "href" path)
101 vertical = rule "vertical" $
103 [ DTC.Comment <$> comment
104 , element "para" $ DTC.Para
107 , element "ol" $ DTC.OL
109 <*> many (element "li" $ many vertical)
110 , element "ul" $ DTC.UL
112 <*> many (element "li" $ many vertical)
113 , element "rl" $ DTC.RL
116 , element "toc" $ DTC.ToC
118 <*> optional (attribute "depth" int)
119 , element "tof" $ DTC.ToF
121 <*> optional (attribute "depth" int)
122 , element "index" $ DTC.Index
127 , anyElem $ \n@XmlName{..} ->
136 <$> attribute "type" text
140 horizontals = many horizontal
141 horizontal = rule "horizontal" $
143 [ DTC.BR <$ element "br" none
144 , DTC.B <$> element "b" horizontals
145 , DTC.Code <$> element "code" horizontals
146 , DTC.Del <$> element "del" horizontals
147 , DTC.I <$> element "i" horizontals
148 , DTC.Note <$> element "note" horizontals
149 , DTC.Q <$> element "q" horizontals
150 , DTC.SC <$> element "sc" horizontals
151 , DTC.Sub <$> element "sub" horizontals
152 , DTC.Sup <$> element "sup" horizontals
153 , DTC.U <$> element "u" horizontals
154 , element "eref" $ DTC.Eref
155 <$> attribute "to" url
157 , element "iref" $ DTC.Iref <$> to <*> horizontals
158 , element "ref" $ DTC.Ref <$> to <*> horizontals
159 , element "rref" $ DTC.Rref <$> to <*> horizontals
162 keyword = rule "keyword" $
163 element "keyword" text
164 version = rule "version" $
166 element "version" text
172 <|?> (Nothing, Just <$> editor)
173 <|?> (Nothing, Just <$> date)
179 author = rule "author" $ element "author" entity
180 editor = rule "editor" $ element "editor" entity
181 entity = rule "entity" $
185 address = rule "address" $
189 <$?> (def, attribute "street" text)
190 <|?> (def, attribute "zipcode" text)
191 <|?> (def, attribute "city" text)
192 <|?> (def, attribute "region" text)
193 <|?> (def, attribute "country" text)
194 <|?> (def, attribute "email" text)
195 <|?> (def, attribute "tel" text)
196 <|?> (def, attribute "fax" text)
197 serie = rule "serie" $
201 <$?> (def, attribute "name" text)
202 <|?> (def, attribute "key" text)
207 <$?> (def, attribute "name" text)
208 <|?> (def, attribute "href" url)
209 <|?> (def, attribute "rel" text)
211 alias = rule "alias" $
216 reference = rule "reference" $
217 element "reference" $
220 <*> optional (attribute "to" url)
223 instance Sym_DTC RNC.Writer
224 instance Sym_DTC RNC.RuleWriter
225 dtcRNC :: [RNC.RuleWriter ()]
233 , void $ rule "horizontals" horizontals
245 , void $ rule "about" $ element "about" about