1 {-# LANGUAGE NoMonomorphismRestriction #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 module Language.DTC.Sym where
5 import Control.Applicative (Applicative(..), (<$>), (<$))
6 import Control.Monad (void)
7 import Data.Default.Class (Default(..))
8 import Data.Foldable (Foldable(..), concat)
9 import Data.Function (($), (.), flip)
10 import Data.Maybe (Maybe(..), maybe)
11 import Data.TreeSeq.Strict (Tree(..), tree0)
12 import qualified Data.Sequence as Seq
13 import qualified Data.Text.Lazy as TL
16 import Language.RNC.Sym as RNC
17 import Language.DTC.Anchor (wordify)
18 import qualified Language.DTC.Document as DTC
19 import qualified Language.RNC.Write as RNC
21 foldlApp :: (Default a, Foldable t) => t (a -> a) -> a
22 foldlApp = foldl' (flip ($)) def
23 foldrApp :: (Default a, Foldable t) => t (a -> a) -> a
24 foldrApp = foldr ($) def
26 class RNC.Sym_RNC repr => Sym_DTC repr where
27 position :: repr DTC.Pos
28 document :: repr DTC.Document
31 about :: repr DTC.About
32 keyword :: repr TL.Text
33 version :: repr MayText
34 author :: repr DTC.Entity
35 editor :: repr DTC.Entity
37 entity :: repr DTC.Entity
39 serie :: repr DTC.Serie
40 alias :: repr DTC.Alias
43 bodyValue :: repr DTC.BodyNode
44 toc :: repr DTC.BodyNode
45 tof :: repr DTC.BodyNode
46 index :: repr DTC.BodyNode
47 figure :: repr DTC.BodyNode
48 references :: repr DTC.BodyNode
49 reference :: repr DTC.Reference
50 include :: repr DTC.Include
52 block :: repr DTC.Block
54 lines :: repr DTC.Lines
56 commonAttrs :: repr DTC.CommonAttrs
58 title :: repr DTC.Title
69 <$?> (def, Just <$> id)
70 <|?> (def, rule "class" $ attribute "class" $ TL.words <$> text)
72 document = rule "document" $
78 <$> optional (rule "about" $ element "about" about)
84 [ element "section" $ Tree <$> section <*> body
101 , DTC.Block <$> block
103 title = rule "title" $ DTC.Title <$> element "title" para
104 name = rule "name" $ attribute "name" text
105 url = rule "url" $ URL <$> text
106 path = rule "path" $ Path <$> text
107 ident = rule "ident" $ Ident <$> text
108 to = rule "to" $ attribute "to" ident
109 id = rule "id" $ attribute "id" ident
114 <$?> (0, attribute "year" int)
115 <|?> (Nothing, Just <$> attribute "month" nat1)
116 <|?> (Nothing, Just <$> attribute "day" nat1)
117 include = rule "include" $
121 <$?> (def, attribute "href" path)
122 block = rule "block" $
124 [ DTC.Comment <$> comment
134 <*> many (element "li" $ many block)
139 <*> many (element "li" $ many block)
140 , element "artwork" $
144 <*> attribute "type" text
150 <*> attribute "type" text
153 , anyElem $ \n@XmlName{..} ->
164 <*> optional (attribute "depth" nat)
189 (wordify <$>) . TL.lines <$> text)
196 <*> attribute "type" text
200 element "references" $
205 para = rule "para" $ (Seq.fromList <$>) $ many lines
209 [ element "b" $ Tree DTC.B <$> para
210 , element "code" $ Tree DTC.Code <$> para
211 , element "del" $ Tree DTC.Del <$> para
212 , element "i" $ Tree DTC.I <$> para
213 , element "note" $ Tree (DTC.Note Nothing) <$> para
214 , element "q" $ Tree DTC.Q <$> para
215 , element "sc" $ Tree DTC.SC <$> para
216 , element "sub" $ Tree DTC.Sub <$> para
217 , element "sup" $ Tree DTC.Sup <$> para
218 , element "u" $ Tree DTC.U <$> para
219 , element "eref" $ Tree . DTC.Eref <$> attribute "to" url <*> para
220 , element "iref" $ Tree . DTC.Iref Nothing . wordify <$> attribute "to" text <*> para
221 , element "ref" $ Tree . DTC.Ref <$> to <*> para
222 , element "rref" $ Tree . DTC.Rref Nothing <$> to <*> para
223 , element "br" $ tree0 DTC.BR <$ none
224 , tree0 . DTC.Plain <$> text
226 keyword = rule "keyword" $
227 element "keyword" text
228 version = rule "version" $
230 element "version" text
235 <|?> (def, Just <$> attribute "url" url)
237 <|?> (Nothing, Just <$> editor)
238 <|?> (Nothing, Just <$> date)
244 author = rule "author" $ element "author" entity
245 editor = rule "editor" $ element "editor" entity
246 entity = rule "entity" $
250 <|?> (def, attribute "street" text)
251 <|?> (def, attribute "zipcode" text)
252 <|?> (def, attribute "city" text)
253 <|?> (def, attribute "region" text)
254 <|?> (def, attribute "country" text)
255 <|?> (def, attribute "email" text)
256 <|?> (def, attribute "tel" text)
257 <|?> (def, attribute "fax" text)
258 <|?> (def, Just <$> attribute "url" url)
259 <|?> (def, Just <$> attribute "org" entity)
260 serie = rule "serie" $
265 <|?> (def, attribute "key" text)
269 (\n h r ls -> DTC.Link n h r (Seq.fromList ls))
271 <|?> (def, attribute "href" url)
272 <|?> (def, attribute "rel" text)
274 alias = rule "alias" $
279 reference = rule "reference" $
280 element "reference" $
285 instance Sym_DTC RNC.Writer where
286 position = RNC.writeText ""
287 instance Sym_DTC RNC.RuleWriter where
288 position = RNC.RuleWriter position
290 dtcRNC :: [RNC.RuleWriter ()]
295 , void $ rule "about" $ element "about" about