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(..), Alternative(..), optional, (<$>), (<$))
11 import Data.Foldable (Foldable,foldl',foldr)
12 import Data.Function (($),(.),flip)
14 import Data.Maybe (Maybe(..), maybe)
15 import Data.Text (Text)
16 import Text.Show (Show)
17 import qualified Data.Text as Text
19 import Language.DTC.Document (Default(..), MayText(..))
20 import Language.TCT.Write.XML (XmlName(..))
21 import qualified Language.DTC.Document as DTC
23 foldlApp :: (DTC.Default a, Foldable t) => t (a -> a) -> a
24 foldlApp = foldl' (flip ($)) def
25 foldrApp :: (DTC.Default a, Foldable t) => t (a -> a) -> a
26 foldrApp = foldr ($) def
28 class (Applicative repr, Alternative repr) => Sym_RNC repr where
29 rule :: Show a => Text -> repr a -> repr a
30 element :: XmlName -> repr a -> repr a
31 attribute :: XmlName -> repr a -> repr a
33 try :: repr a -> repr a
35 anyElem :: Show a => (XmlName -> repr a) -> repr a
41 choice :: [repr a] -> repr a
42 intermany :: [repr a] -> repr [a]
43 intermany = many . choice . (try <$>)
45 type Perm repr = (r :: * -> *) | r -> repr
46 interleaved :: Perm repr a -> repr a
47 (<$$>) :: (a -> b) -> repr a -> Perm repr b
49 (<$?>) :: (a -> b) -> (a,repr a) -> Perm repr b
50 (<||>) :: Perm repr (a -> b) -> repr a -> Perm repr b
51 (<|?>) :: Perm repr (a -> b) -> (a,repr a) -> Perm repr b
53 (<$*>) :: ([a] -> b) -> repr a -> Perm repr b
54 (<|*>) :: Perm repr ([a] -> b) -> repr a -> Perm repr b
56 infixl 2 <$$>, <$?>, <$*>
57 infixl 1 <||>, <|?>, <|*>
59 class Sym_RNC repr => Sym_DTC repr where
60 title :: repr DTC.Title
64 ident :: repr DTC.Ident
68 include :: repr DTC.Include
69 horizontals :: repr DTC.Horizontals
70 horizontal :: repr DTC.Horizontal
71 verticals :: repr DTC.Verticals
72 vertical :: repr DTC.Vertical
73 reference :: repr DTC.Reference
74 document :: repr DTC.Document
76 about :: repr DTC.About
78 version :: repr MayText
79 author :: repr DTC.Entity
80 editor :: repr DTC.Entity
81 entity :: repr DTC.Entity
82 address :: repr DTC.Address
84 serie :: repr DTC.Serie
85 alias :: repr DTC.Alias
86 commonAttrs :: repr DTC.CommonAttrs
91 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
93 document = rule "document" $
110 <$> optional (rule "about" $ element "about" about)
111 title = rule "title" $ DTC.Title <$> element "title" horizontals
112 name = rule "name" $ attribute "name" text
113 url = rule "url" $ DTC.URL <$> text
114 path = rule "path" $ DTC.Path <$> text
115 ident = rule "ident" $ DTC.Ident <$> text
116 to = rule "to" $ attribute "to" ident
117 id = rule "id" $ attribute "id" ident
122 <$?> (0, attribute "year" int)
123 <|?> (Nothing, Just <$> attribute "month" nat1)
124 <|?> (Nothing, Just <$> attribute "day" nat1)
125 include = rule "include" $
129 <$?> (def, attribute "href" path)
130 verticals = many vertical
131 vertical = rule "vertical" $
133 [ DTC.Comment <$> comment
134 , element "para" $ DTC.Para
137 , element "ol" $ DTC.OL
139 <*> many (element "li" verticals)
140 , element "ul" $ DTC.UL
142 <*> many (element "li" verticals)
143 , element "rl" $ DTC.RL
146 , element "toc" $ DTC.ToC
148 <*> optional (attribute "depth" int)
149 , element "tof" $ DTC.ToF
151 <*> optional (attribute "depth" int)
152 , element "index" $ DTC.Index
155 , anyElem $ \XmlName{..} ->
161 <*> pure xmlNameLocal
165 horizontals = many horizontal
166 horizontal = rule "horizontal" $
168 [ DTC.BR <$ element "br" none
169 , DTC.B <$> element "b" horizontals
170 , DTC.Code <$> element "code" horizontals
171 , DTC.Del <$> element "del" horizontals
172 , DTC.I <$> element "i" horizontals
173 , DTC.Note <$> element "note" horizontals
174 , DTC.Q <$> element "q" horizontals
175 , DTC.SC <$> element "sc" horizontals
176 , DTC.Sub <$> element "sub" horizontals
177 , DTC.Sup <$> element "sup" horizontals
178 , DTC.U <$> element "u" horizontals
179 , element "eref" $ DTC.Eref
180 <$> attribute "to" url
182 , element "iref" $ DTC.Iref <$> to <*> horizontals
183 , element "ref" $ DTC.Ref <$> to <*> horizontals
184 , element "rref" $ DTC.Rref <$> to <*> horizontals
187 keyword = rule "keyword" $
188 element "keyword" text
189 version = rule "version" $
191 element "version" text
197 <|?> (Nothing, Just <$> editor)
198 <|?> (Nothing, Just <$> date)
204 author = rule "author" $ element "author" entity
205 editor = rule "editor" $ element "editor" entity
206 entity = rule "entity" $
210 address = rule "address" $
214 <$?> (def, attribute "street" text)
215 <|?> (def, attribute "zipcode" text)
216 <|?> (def, attribute "city" text)
217 <|?> (def, attribute "region" text)
218 <|?> (def, attribute "country" text)
219 <|?> (def, attribute "email" text)
220 <|?> (def, attribute "tel" text)
221 <|?> (def, attribute "fax" text)
222 serie = rule "serie" $
226 <$?> (def, attribute "name" text)
227 <|?> (def, attribute "key" text)
232 <$?> (def, attribute "name" text)
233 <|?> (def, attribute "href" url)
234 <|?> (def, attribute "rel" text)
236 alias = rule "alias" $
241 reference = rule "reference" $
242 element "reference" $
245 <*> optional (attribute "to" url)
249 , element "figure" $ ul