1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
3 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE StandaloneDeriving #-}
5 module Language.DTC.Sym where
7 import Control.Applicative (Applicative(..), (<$>), (<$))
8 import Control.Monad (void)
9 import Data.Default.Class (Default(..))
10 import Data.Foldable (Foldable(..), concat)
11 import Data.Function (($), (.), flip)
12 import Data.Maybe (Maybe(..), maybe)
13 import Data.Text (Text)
14 import Data.TreeSeq.Strict (Tree(..))
15 import qualified Data.Sequence as Seq
16 import qualified Data.Text as Text
19 import Language.RNC.Sym as RNC
20 import Language.DTC.Anchor (wordify)
21 import qualified Language.DTC.Document as DTC
22 import qualified Language.RNC.Write as RNC
24 foldlApp :: (Default a, Foldable t) => t (a -> a) -> a
25 foldlApp = foldl' (flip ($)) def
26 foldrApp :: (Default a, Foldable t) => t (a -> a) -> a
27 foldrApp = foldr ($) def
29 class RNC.Sym_RNC repr => Sym_DTC repr where
30 position :: repr DTC.Pos
31 document :: repr DTC.Document
34 about :: repr DTC.About
36 version :: repr MayText
37 author :: repr DTC.Entity
38 editor :: repr DTC.Entity
40 entity :: repr DTC.Entity
42 serie :: repr DTC.Serie
43 alias :: repr DTC.Alias
46 bodyValue :: repr DTC.BodyValue
47 toc :: repr DTC.BodyValue
48 tof :: repr DTC.BodyValue
49 index :: repr DTC.BodyValue
50 figure :: repr DTC.BodyValue
51 references :: repr DTC.BodyValue
52 reference :: repr DTC.Reference
53 include :: repr DTC.Include
55 block :: repr DTC.Block
57 lines :: repr (Tree DTC.LineKey DTC.LineValue)
59 commonAttrs :: repr DTC.CommonAttrs
61 title :: repr DTC.Title
72 <$?> (def, Just <$> id)
73 <|?> (def, rule "class" $ attribute "class" $ Text.words <$> text)
75 document = rule "document" $
81 <$> optional (rule "about" $ element "about" about)
87 [ element "section" $ TreeN <$> section <*> body
104 , DTC.Block <$> block
106 title = rule "title" $ DTC.Title <$> element "title" para
107 name = rule "name" $ attribute "name" text
108 url = rule "url" $ URL <$> text
109 path = rule "path" $ Path <$> text
110 ident = rule "ident" $ Ident <$> text
111 to = rule "to" $ attribute "to" ident
112 id = rule "id" $ attribute "id" ident
117 <$?> (0, attribute "year" int)
118 <|?> (Nothing, Just <$> attribute "month" nat1)
119 <|?> (Nothing, Just <$> attribute "day" nat1)
120 include = rule "include" $
124 <$?> (def, attribute "href" path)
125 block = rule "block" $
127 [ DTC.Comment <$> comment
137 <*> many (element "li" $ many block)
142 <*> many (element "li" $ many block)
144 , anyElem $ \n@XmlName{..} ->
155 <*> optional (attribute "depth" nat)
180 (wordify <$>) . Text.lines <$> text)
187 <*> attribute "type" text
191 element "references" $
196 para = rule "para" $ (Seq.fromList <$>) $ many lines
200 [ element "b" $ TreeN DTC.B <$> para
201 , element "code" $ TreeN DTC.Code <$> para
202 , element "del" $ TreeN DTC.Del <$> para
203 , element "i" $ TreeN DTC.I <$> para
204 , element "note" $ TreeN (DTC.Note Nothing) <$> para
205 , element "q" $ TreeN DTC.Q <$> para
206 , element "sc" $ TreeN DTC.SC <$> para
207 , element "sub" $ TreeN DTC.Sub <$> para
208 , element "sup" $ TreeN DTC.Sup <$> para
209 , element "u" $ TreeN DTC.U <$> para
210 , element "eref" $ TreeN . DTC.Eref <$> attribute "to" url <*> para
211 , element "iref" $ TreeN . DTC.Iref Nothing . wordify <$> attribute "to" text <*> para
212 , element "ref" $ TreeN . DTC.Ref <$> to <*> para
213 , element "rref" $ TreeN . DTC.Rref Nothing <$> to <*> para
214 , element "br" $ Tree0 DTC.BR <$ none
215 , Tree0 . DTC.Plain <$> text
217 keyword = rule "keyword" $
218 element "keyword" text
219 version = rule "version" $
221 element "version" text
226 <|?> (def, Just <$> attribute "url" url)
228 <|?> (Nothing, Just <$> editor)
229 <|?> (Nothing, Just <$> date)
235 author = rule "author" $ element "author" entity
236 editor = rule "editor" $ element "editor" entity
237 entity = rule "entity" $
241 <|?> (def, attribute "street" text)
242 <|?> (def, attribute "zipcode" text)
243 <|?> (def, attribute "city" text)
244 <|?> (def, attribute "region" text)
245 <|?> (def, attribute "country" text)
246 <|?> (def, attribute "email" text)
247 <|?> (def, attribute "tel" text)
248 <|?> (def, attribute "fax" text)
249 <|?> (def, Just <$> attribute "url" url)
250 <|?> (def, Just <$> attribute "org" entity)
251 serie = rule "serie" $
256 <|?> (def, attribute "key" text)
260 (\n h r ls -> DTC.Link n h r (Seq.fromList ls))
262 <|?> (def, attribute "href" url)
263 <|?> (def, attribute "rel" text)
265 alias = rule "alias" $
270 reference = rule "reference" $
271 element "reference" $
276 instance Sym_DTC RNC.Writer where
277 position = RNC.writeText ""
278 instance Sym_DTC RNC.RuleWriter where
279 position = RNC.RuleWriter position
281 dtcRNC :: [RNC.RuleWriter ()]
286 , void $ rule "about" $ element "about" about