0 | module Language.XML.Prolog.XMLDecl
2 | import Data.String.Parser
4 | import Language.XML.Attribute
8 | constructor MkXMLDecl
10 | encoding : Maybe String
11 | standalone : Maybe Bool
18 | <?xml version=\{show decl.version}\
19 | \{maybe "" (\e => " encoding=" ++ show e) decl.encoding}\
20 | \{maybe "" (\s => " standalone=" ++ if s then "\"yes\"" else "\"no\"") decl.standalone}\
25 | xmlDecl : Parser XMLDecl
27 | ignore $
string "<?xml"
29 | version <- exactAttribute $
MkQName Nothing $
MkName "version"
30 | encoding <- optional (spaces *> exactAttribute (MkQName Nothing $
MkName "encoding"))
31 | standalone <- case !(optional (spaces *> exactAttribute (MkQName Nothing $
MkName "standalone"))) of
32 | Just "yes" => pure $
Just True
33 | Just "no" => pure $
Just False
34 | Nothing => pure Nothing
35 | Just value => fail "Expect \"yes\"/\"no\" for \"standalone\" attribute, got: \{show value}"
37 | ignore $
string "?>"
38 | pure $
MkXMLDecl version encoding standalone
39 | ) <?> "XML declaration"