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)
83 title = rule "title" $ DTC.Title <$> element "title" horizontals
84 name = rule "name" $ attribute "name" text
85 url = rule "url" $ DTC.URL <$> text
86 path = rule "path" $ DTC.Path <$> text
87 ident = rule "ident" $ DTC.Ident <$> text
88 to = rule "to" $ attribute "to" ident
89 id = rule "id" $ attribute "id" ident
94 <$?> (0, attribute "year" int)
95 <|?> (Nothing, Just <$> attribute "month" nat1)
96 <|?> (Nothing, Just <$> attribute "day" nat1)
97 include = rule "include" $
101 <$?> (def, attribute "href" path)
102 vertical = rule "vertical" $
104 [ DTC.Comment <$> comment
114 <*> many (element "li" $ many vertical)
119 <*> many (element "li" $ many vertical)
129 <*> optional (attribute "depth" int)
134 <*> optional (attribute "depth" int)
142 , anyElem $ \n@XmlName{..} ->
152 <$> attribute "type" text
156 horizontals = many horizontal
157 horizontal = rule "horizontal" $
159 [ DTC.BR <$ element "br" none
160 , DTC.B <$> element "b" horizontals
161 , DTC.Code <$> element "code" horizontals
162 , DTC.Del <$> element "del" horizontals
163 , DTC.I <$> element "i" horizontals
164 , DTC.Note <$> element "note" horizontals
165 , DTC.Q <$> element "q" horizontals
166 , DTC.SC <$> element "sc" horizontals
167 , DTC.Sub <$> element "sub" horizontals
168 , DTC.Sup <$> element "sup" horizontals
169 , DTC.U <$> element "u" horizontals
170 , element "eref" $ DTC.Eref
171 <$> attribute "to" url
173 , element "iref" $ DTC.Iref <$> to <*> horizontals
174 , element "ref" $ DTC.Ref <$> to <*> horizontals
175 , element "rref" $ DTC.Rref <$> to <*> horizontals
178 keyword = rule "keyword" $
179 element "keyword" text
180 version = rule "version" $
182 element "version" text
188 <|?> (Nothing, Just <$> editor)
189 <|?> (Nothing, Just <$> date)
195 author = rule "author" $ element "author" entity
196 editor = rule "editor" $ element "editor" entity
197 entity = rule "entity" $
201 address = rule "address" $
205 <$?> (def, attribute "street" text)
206 <|?> (def, attribute "zipcode" text)
207 <|?> (def, attribute "city" text)
208 <|?> (def, attribute "region" text)
209 <|?> (def, attribute "country" text)
210 <|?> (def, attribute "email" text)
211 <|?> (def, attribute "tel" text)
212 <|?> (def, attribute "fax" text)
213 serie = rule "serie" $
217 <$?> (def, attribute "name" text)
218 <|?> (def, attribute "key" text)
223 <$?> (def, attribute "name" text)
224 <|?> (def, attribute "href" url)
225 <|?> (def, attribute "rel" text)
227 alias = rule "alias" $
232 reference = rule "reference" $
233 element "reference" $
236 <*> optional (attribute "to" url)
239 instance Sym_DTC RNC.Writer
240 instance Sym_DTC RNC.RuleWriter
241 dtcRNC :: [RNC.RuleWriter ()]
249 , void $ rule "horizontals" horizontals
261 , void $ rule "about" $ element "about" about