1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE NamedFieldPuns #-}
4 {-# LANGUAGE NoMonomorphismRestriction #-}
5 {-# LANGUAGE OverloadedStrings #-}
6 {-# LANGUAGE RecordWildCards #-}
7 {-# LANGUAGE TypeFamilyDependencies #-}
8 module Language.DTC.Sym where
10 import Control.Applicative (Applicative(..), (<$>), (<$))
11 import Control.Monad (void)
12 import Data.Foldable (Foldable,foldl',foldr)
13 import Data.Function (($),(.),flip)
15 import Data.Maybe (Maybe(..), maybe)
16 import Data.Text (Text)
17 import Text.Show (Show)
18 import qualified Data.Text as Text
20 import Language.DTC.Document (Default(..), MayText(..))
21 import Language.TCT.Write.XML (XmlName(..))
22 import qualified Language.DTC.Document as DTC
23 import Language.RNC.Sym as RNC
24 import qualified Language.RNC.Write as RNC
26 foldlApp :: (DTC.Default a, Foldable t) => t (a -> a) -> a
27 foldlApp = foldl' (flip ($)) def
28 foldrApp :: (DTC.Default a, Foldable t) => t (a -> a) -> a
29 foldrApp = foldr ($) def
31 class RNC.Sym_RNC repr => Sym_DTC repr where
32 title :: repr DTC.Title
36 ident :: repr DTC.Ident
40 include :: repr DTC.Include
41 horizontals :: repr DTC.Horizontals
42 horizontal :: repr DTC.Horizontal
43 vertical :: repr DTC.Vertical
44 reference :: repr DTC.Reference
45 document :: repr DTC.Document
47 body :: repr [DTC.Body]
48 about :: repr DTC.About
50 version :: repr MayText
51 author :: repr DTC.Entity
52 editor :: repr DTC.Entity
53 entity :: repr DTC.Entity
54 address :: repr DTC.Address
56 serie :: repr DTC.Serie
57 alias :: repr DTC.Alias
58 figure :: repr DTC.Vertical
59 commonAttrs :: repr DTC.CommonAttrs
65 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
67 document = rule "document" $
73 <$> optional (rule "about" $ element "about" about)
88 title = rule "title" $ DTC.Title <$> element "title" horizontals
89 name = rule "name" $ attribute "name" text
90 url = rule "url" $ DTC.URL <$> text
91 path = rule "path" $ DTC.Path <$> text
92 ident = rule "ident" $ DTC.Ident <$> text
93 to = rule "to" $ attribute "to" ident
94 id = rule "id" $ attribute "id" ident
99 <$?> (0, attribute "year" int)
100 <|?> (Nothing, Just <$> attribute "month" nat1)
101 <|?> (Nothing, Just <$> attribute "day" nat1)
102 include = rule "include" $
106 <$?> (def, attribute "href" path)
107 vertical = rule "vertical" $
109 [ DTC.Comment <$> comment
110 , element "para" $ DTC.Para
113 , element "ol" $ DTC.OL
115 <*> many (element "li" $ many vertical)
116 , element "ul" $ DTC.UL
118 <*> many (element "li" $ many vertical)
119 , element "rl" $ DTC.RL
122 , element "toc" $ DTC.ToC
124 <*> optional (attribute "depth" int)
125 , element "tof" $ DTC.ToF
127 <*> optional (attribute "depth" int)
128 , element "index" $ DTC.Index
133 , anyElem $ \n@XmlName{..} ->
142 <$> attribute "type" text
146 horizontals = many horizontal
147 horizontal = rule "horizontal" $
149 [ DTC.BR <$ element "br" none
150 , DTC.B <$> element "b" horizontals
151 , DTC.Code <$> element "code" horizontals
152 , DTC.Del <$> element "del" horizontals
153 , DTC.I <$> element "i" horizontals
154 , DTC.Note <$> element "note" horizontals
155 , DTC.Q <$> element "q" horizontals
156 , DTC.SC <$> element "sc" horizontals
157 , DTC.Sub <$> element "sub" horizontals
158 , DTC.Sup <$> element "sup" horizontals
159 , DTC.U <$> element "u" horizontals
160 , element "eref" $ DTC.Eref
161 <$> attribute "to" url
163 , element "iref" $ DTC.Iref <$> to <*> horizontals
164 , element "ref" $ DTC.Ref <$> to <*> horizontals
165 , element "rref" $ DTC.Rref <$> to <*> horizontals
168 keyword = rule "keyword" $
169 element "keyword" text
170 version = rule "version" $
172 element "version" text
178 <|?> (Nothing, Just <$> editor)
179 <|?> (Nothing, Just <$> date)
185 author = rule "author" $ element "author" entity
186 editor = rule "editor" $ element "editor" entity
187 entity = rule "entity" $
191 address = rule "address" $
195 <$?> (def, attribute "street" text)
196 <|?> (def, attribute "zipcode" text)
197 <|?> (def, attribute "city" text)
198 <|?> (def, attribute "region" text)
199 <|?> (def, attribute "country" text)
200 <|?> (def, attribute "email" text)
201 <|?> (def, attribute "tel" text)
202 <|?> (def, attribute "fax" text)
203 serie = rule "serie" $
207 <$?> (def, attribute "name" text)
208 <|?> (def, attribute "key" text)
213 <$?> (def, attribute "name" text)
214 <|?> (def, attribute "href" url)
215 <|?> (def, attribute "rel" text)
217 alias = rule "alias" $
222 reference = rule "reference" $
223 element "reference" $
226 <*> optional (attribute "to" url)
229 instance Sym_DTC RNC.Writer
230 instance Sym_DTC RNC.RuleWriter
231 dtcRNC :: [RNC.RuleWriter ()]
239 , void $ rule "horizontals" horizontals
251 , void $ rule "about" $ element "about" about