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 verticals :: repr DTC.Verticals
44 vertical :: repr DTC.Vertical
45 reference :: repr DTC.Reference
46 document :: repr DTC.Document
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 :: XmlName -> repr DTC.Vertical
59 commonAttrs :: repr DTC.CommonAttrs
65 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
67 document = rule "document" $
84 <$> optional (rule "about" $ element "about" about)
85 title = rule "title" $ DTC.Title <$> element "title" horizontals
86 name = rule "name" $ attribute "name" text
87 url = rule "url" $ DTC.URL <$> text
88 path = rule "path" $ DTC.Path <$> text
89 ident = rule "ident" $ DTC.Ident <$> text
90 to = rule "to" $ attribute "to" ident
91 id = rule "id" $ attribute "id" ident
96 <$?> (0, attribute "year" int)
97 <|?> (Nothing, Just <$> attribute "month" nat1)
98 <|?> (Nothing, Just <$> attribute "day" nat1)
99 include = rule "include" $
103 <$?> (def, attribute "href" path)
104 verticals = many vertical
105 vertical = rule "vertical" $
107 [ DTC.Comment <$> comment
108 , element "para" $ DTC.Para
111 , element "ol" $ DTC.OL
113 <*> many (element "li" verticals)
114 , element "ul" $ DTC.UL
116 <*> many (element "li" verticals)
117 , element "rl" $ DTC.RL
120 , element "toc" $ DTC.ToC
122 <*> optional (attribute "depth" int)
123 , element "tof" $ DTC.ToF
125 <*> optional (attribute "depth" int)
126 , element "index" $ DTC.Index
129 , anyElem $ \n@XmlName{..} ->
135 (`DTC.Figure` xmlNameLocal)
139 horizontals = many horizontal
140 horizontal = rule "horizontal" $
142 [ DTC.BR <$ element "br" none
143 , DTC.B <$> element "b" horizontals
144 , DTC.Code <$> element "code" horizontals
145 , DTC.Del <$> element "del" horizontals
146 , DTC.I <$> element "i" horizontals
147 , DTC.Note <$> element "note" horizontals
148 , DTC.Q <$> element "q" horizontals
149 , DTC.SC <$> element "sc" horizontals
150 , DTC.Sub <$> element "sub" horizontals
151 , DTC.Sup <$> element "sup" horizontals
152 , DTC.U <$> element "u" horizontals
153 , element "eref" $ DTC.Eref
154 <$> attribute "to" url
156 , element "iref" $ DTC.Iref <$> to <*> horizontals
157 , element "ref" $ DTC.Ref <$> to <*> horizontals
158 , element "rref" $ DTC.Rref <$> to <*> horizontals
161 keyword = rule "keyword" $
162 element "keyword" text
163 version = rule "version" $
165 element "version" text
171 <|?> (Nothing, Just <$> editor)
172 <|?> (Nothing, Just <$> date)
178 author = rule "author" $ element "author" entity
179 editor = rule "editor" $ element "editor" entity
180 entity = rule "entity" $
184 address = rule "address" $
188 <$?> (def, attribute "street" text)
189 <|?> (def, attribute "zipcode" text)
190 <|?> (def, attribute "city" text)
191 <|?> (def, attribute "region" text)
192 <|?> (def, attribute "country" text)
193 <|?> (def, attribute "email" text)
194 <|?> (def, attribute "tel" text)
195 <|?> (def, attribute "fax" text)
196 serie = rule "serie" $
200 <$?> (def, attribute "name" text)
201 <|?> (def, attribute "key" text)
206 <$?> (def, attribute "name" text)
207 <|?> (def, attribute "href" url)
208 <|?> (def, attribute "rel" text)
210 alias = rule "alias" $
215 reference = rule "reference" $
216 element "reference" $
219 <*> optional (attribute "to" url)
223 , element "figure" $ ul
230 instance Sym_DTC RNC.Writer
231 instance Sym_DTC RNC.RuleWriter
232 dtcRNC :: [RNC.RuleWriter ()]
243 , void $ rule "horizontals" horizontals
245 , void $ rule "verticals" verticals
247 , void $ figure "<element>"
251 , void $ rule "about" $ element "about" about