0 | module Language.XML.Prolog.DocType
 1 |
 2 | import Data.String.Parser
 3 |
 4 | import Language.XML.Attribute
 5 |
 6 | public export
 7 | data ExternalID = System String | Public String String
 8 |
 9 | %name ExternalID externalID
10 |
11 | export
12 | Show ExternalID where
13 |     show (System sysID) = "SYSTEM \{show sysID}"
14 |     show (Public pubID sysID) = "PUBLIC \{show pubID} \{show sysID}"
15 |
16 | public export
17 | record DocType where
18 |     constructor MkDocType
19 |     name : String
20 |     externalID : Maybe ExternalID
21 |
22 | export
23 | Show DocType where
24 |     show docType = """
25 |                    <!DOCTYPE \{docType.name}\
26 |                    \{maybe "" (\eID => " " ++ show eID) docType.externalID}\
27 |                    >
28 |                    """
29 |
30 | export
31 | systemID : Parser ExternalID
32 | systemID = do
33 |     ignore $ string "SYSTEM"
34 |     spaces1
35 |     System <$> quotedString
36 |
37 | export
38 | publicID : Parser ExternalID
39 | publicID = do
40 |     ignore $ string "PUBLIC"
41 |     spaces1
42 |     pubID <- quotedString
43 |     spaces1
44 |     sysID <- quotedString
45 |     pure $ Public pubID sysID
46 |
47 | export
48 | externalID : Parser ExternalID
49 | externalID = systemID <|> publicID
50 |
51 | export
52 | docType : Parser DocType
53 | docType = (do
54 |     ignore $ string "<!DOCTYPE"
55 |     spaces1
56 |     name <- pack <$> many letter
57 |     externalID <- optional (spaces1 *> externalID)
58 |     spaces
59 |     ignore $ string ">"
60 |     pure $ MkDocType name externalID
61 |   ) <?> "XML document type"
62 |