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.Text (Text)
12 import Data.TreeSeq.Strict (Tree(..))
13 import qualified Data.Sequence as Seq
14 import qualified Data.Text as Text
17 import Language.RNC.Sym as RNC
18 import Language.DTC.Index (wordify)
19 import qualified Language.DTC.Document as DTC
20 import qualified Language.RNC.Write as RNC
22 foldlApp :: (Default a, Foldable t) => t (a -> a) -> a
23 foldlApp = foldl' (flip ($)) def
24 foldrApp :: (Default a, Foldable t) => t (a -> a) -> a
25 foldrApp = foldr ($) def
27 class RNC.Sym_RNC repr => Sym_DTC repr where
28 document :: repr DTC.Document
31 about :: repr DTC.About
33 version :: repr MayText
34 author :: repr DTC.Entity
35 editor :: repr DTC.Entity
37 entity :: repr DTC.Entity
38 address :: repr DTC.Address
40 serie :: repr DTC.Serie
41 alias :: repr DTC.Alias
44 bodyValue :: repr DTC.BodyValue
45 toc :: repr DTC.BodyValue
46 tof :: repr DTC.BodyValue
47 index :: repr DTC.BodyValue
48 figure :: repr DTC.BodyValue
49 reference :: repr DTC.Reference
50 include :: repr DTC.Include
52 block :: repr DTC.Block
54 lines :: repr (Tree DTC.LineKey DTC.LineValue)
56 commonAttrs :: repr DTC.CommonAttrs
58 title :: repr DTC.Title
69 <$?> (def, Just <$> id)
70 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
72 document = rule "document" $
78 <$> optional (rule "about" $ element "about" about)
84 [ element "section" $ TreeN <$> section <*> body
100 , DTC.Block <$> block
102 title = rule "title" $ DTC.Title <$> element "title" para
103 name = rule "name" $ attribute "name" text
104 url = rule "url" $ URL <$> text
105 path = rule "path" $ Path <$> text
106 ident = rule "ident" $ Ident <$> text
107 to = rule "to" $ attribute "to" ident
108 id = rule "id" $ attribute "id" ident
113 <$?> (0, attribute "year" int)
114 <|?> (Nothing, Just <$> attribute "month" nat1)
115 <|?> (Nothing, Just <$> attribute "day" nat1)
116 include = rule "include" $
120 <$?> (def, attribute "href" path)
121 block = rule "block" $
123 [ DTC.Comment <$> comment
133 <*> many (element "li" $ many block)
138 <*> many (element "li" $ many block)
145 , anyElem $ \n@XmlName{..} ->
156 <*> optional (attribute "depth" nat)
163 <*> optional (attribute "depth" nat)
176 (wordify <$>) . Text.lines <$> text)
183 <*> attribute "type" text
186 para = rule "para" $ (Seq.fromList <$>) $ many lines
189 [ element "b" $ TreeN DTC.B <$> para
190 , element "code" $ TreeN DTC.Code <$> para
191 , element "del" $ TreeN DTC.Del <$> para
192 , element "i" $ TreeN DTC.I <$> para
193 , element "note" $ TreeN DTC.Note <$> para
194 , element "q" $ TreeN DTC.Q <$> para
195 , element "sc" $ TreeN DTC.SC <$> para
196 , element "sub" $ TreeN DTC.Sub <$> para
197 , element "sup" $ TreeN DTC.Sup <$> para
198 , element "u" $ TreeN DTC.U <$> para
199 , element "eref" $ TreeN . DTC.Eref <$> attribute "to" url <*> para
200 , element "iref" $ TreeN . DTC.Iref (-1) . wordify <$> attribute "to" text <*> para
201 , element "ref" $ TreeN . DTC.Ref <$> to <*> para
202 , element "rref" $ TreeN . DTC.Rref <$> to <*> para
203 , element "br" $ Tree0 DTC.BR <$ none
204 , Tree0 . DTC.Plain <$> text
206 keyword = rule "keyword" $
207 element "keyword" text
208 version = rule "version" $
210 element "version" text
216 <|?> (Nothing, Just <$> editor)
217 <|?> (Nothing, Just <$> date)
223 author = rule "author" $ element "author" entity
224 editor = rule "editor" $ element "editor" entity
225 entity = rule "entity" $
229 address = rule "address" $
233 <$?> (def, attribute "street" text)
234 <|?> (def, attribute "zipcode" text)
235 <|?> (def, attribute "city" text)
236 <|?> (def, attribute "region" text)
237 <|?> (def, attribute "country" text)
238 <|?> (def, attribute "email" text)
239 <|?> (def, attribute "tel" text)
240 <|?> (def, attribute "fax" text)
241 serie = rule "serie" $
245 <$?> (def, attribute "name" text)
246 <|?> (def, attribute "key" text)
250 (\n h r ls -> DTC.Link n h r (Seq.fromList ls))
251 <$?> (def, attribute "name" text)
252 <|?> (def, attribute "href" url)
253 <|?> (def, attribute "rel" text)
255 alias = rule "alias" $
260 reference = rule "reference" $
261 element "reference" $
264 <*> optional (attribute "to" url)
267 instance Sym_DTC RNC.Writer
268 instance Sym_DTC RNC.RuleWriter
269 dtcRNC :: [RNC.RuleWriter ()]
274 , void $ rule "about" $ element "about" about