{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Chart.Markup.Parser
( markupP,
contentP,
XmlDocument (..),
xmlDocument,
xmlProlog,
xmlXMLDecl,
xmlDoctypedecl,
XmlMiscType,
XmlMisc (..),
xmlMisc,
xmlComment,
lt,
gt,
gtc,
oct,
sq,
dq,
wrappedQ,
wrappedQNoGuard,
eq,
xmlName,
xmlAtt,
openTag,
closeTag,
emptyElemTag,
exampleDocument,
)
where
import Chart.FlatParse
import Chart.Markup
( Content (..),
Markup (Markup),
attribute,
)
import Data.ByteString (ByteString)
import Data.String.Interpolate
import FlatParse.Basic hiding (cut)
import FlatParse.Basic.Text qualified as T
import GHC.Generics
import Prelude
lt :: Parser e ()
lt :: forall e. Parser e ()
lt = $(char '<')
gt :: Parser e ()
gt :: forall e. Parser e ()
gt = $(char '>')
gtc :: Parser e ()
gtc :: forall e. Parser e ()
gtc = $(string "/>")
oct :: Parser e ()
oct :: forall e. Parser e ()
oct = $(string "</")
sq :: ParserT st e ()
sq :: forall (st :: ZeroBitType) e. ParserT st e ()
sq = $(char '\'')
dq :: ParserT st e ()
dq :: forall (st :: ZeroBitType) e. ParserT st e ()
dq = $(char '"')
wrappedDq :: Parser e ByteString
wrappedDq :: forall e. Parser e ByteString
wrappedDq = forall e a. Parser e () -> Parser e a -> Parser e a
wrapped forall (st :: ZeroBitType) e. ParserT st e ()
dq (forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall (st :: ZeroBitType) e. (Char -> Bool) -> ParserT st e Char
T.satisfy (forall a. Eq a => a -> a -> Bool
/= Char
'"')))
wrappedSq :: Parser e ByteString
wrappedSq :: forall e. Parser e ByteString
wrappedSq = forall e a. Parser e () -> Parser e a -> Parser e a
wrapped forall (st :: ZeroBitType) e. ParserT st e ()
sq (forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall (st :: ZeroBitType) e. (Char -> Bool) -> ParserT st e Char
T.satisfy (forall a. Eq a => a -> a -> Bool
/= Char
'\'')))
wrappedQ :: Parser e ByteString
wrappedQ :: forall e. Parser e ByteString
wrappedQ =
forall e. Parser e ByteString
wrappedDq
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e a -> ParserT st e a
<|> forall e. Parser e ByteString
wrappedSq
wrappedQNoGuard :: Parser e a -> Parser e a
wrappedQNoGuard :: forall e a. Parser e a -> Parser e a
wrappedQNoGuard Parser e a
p = forall e a. Parser e () -> Parser e a -> Parser e a
wrapped forall (st :: ZeroBitType) e. ParserT st e ()
dq Parser e a
p forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e a -> ParserT st e a
<|> forall e a. Parser e () -> Parser e a -> Parser e a
wrapped forall (st :: ZeroBitType) e. ParserT st e ()
sq Parser e a
p
eq :: Parser e ()
eq :: forall e. Parser e ()
eq = forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wss forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> $(char '=') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wss
nameStartChar :: Parser e Char
nameStartChar :: forall e. Parser e Char
nameStartChar = forall (st :: ZeroBitType) e.
(Char -> Bool)
-> (Char -> Bool)
-> (Char -> Bool)
-> (Char -> Bool)
-> ParserT st e Char
fusedSatisfy Char -> Bool
isLatinLetter Char -> Bool
isNameStartChar Char -> Bool
isNameStartChar Char -> Bool
isNameStartChar
isNameStartChar :: Char -> Bool
isNameStartChar :: Char -> Bool
isNameStartChar Char
x =
(Char
x forall a. Ord a => a -> a -> Bool
>= Char
'a' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'z')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'A' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'Z')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
':')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
'_')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xC0' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xD6')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xD8' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xF6')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xF8' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x2FF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x370' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x37D')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x37F' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x1FFF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x200C' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x200D')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x2070' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x218F')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x2C00' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x2FEF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x3001' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xD7FF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xF900' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xFDCF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xFDF0' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xFFFD')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x10000' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xEFFFF')
nameChar :: Parser e Char
nameChar :: forall e. Parser e Char
nameChar = forall (st :: ZeroBitType) e.
(Char -> Bool)
-> (Char -> Bool)
-> (Char -> Bool)
-> (Char -> Bool)
-> ParserT st e Char
fusedSatisfy Char -> Bool
isNameCharAscii Char -> Bool
isNameCharExt Char -> Bool
isNameCharExt Char -> Bool
isNameCharExt
isNameCharAscii :: Char -> Bool
isNameCharAscii :: Char -> Bool
isNameCharAscii Char
x =
(Char
x forall a. Ord a => a -> a -> Bool
>= Char
'a' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'z')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'A' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'Z')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'9')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
':')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
'_')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
'-')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
'.')
isNameCharExt :: Char -> Bool
isNameCharExt :: Char -> Bool
isNameCharExt Char
x =
(Char
x forall a. Ord a => a -> a -> Bool
>= Char
'a' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'z')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'A' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'Z')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'9')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
':')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
'_')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
'-')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
'.')
Bool -> Bool -> Bool
|| (Char
x forall a. Eq a => a -> a -> Bool
== Char
'\xB7')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xC0' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xD6')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xD8' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xF6')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xF8' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x2FF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x300' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x36F')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x370' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x37D')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x37F' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x1FFF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x200C' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x200D')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x203F' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x2040')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x2070' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x218F')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x2C00' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\x2FEF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x3001' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xD7FF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xF900' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xFDCF')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\xFDF0' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xFFFD')
Bool -> Bool -> Bool
|| (Char
x forall a. Ord a => a -> a -> Bool
>= Char
'\x10000' Bool -> Bool -> Bool
&& Char
x forall a. Ord a => a -> a -> Bool
<= Char
'\xEFFFF')
xmlName :: Parser e ByteString
xmlName :: forall e. Parser e ByteString
xmlName = forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf (forall e. Parser e Char
nameStartChar forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall e. Parser e Char
nameChar)
xmlAtt :: Parser e (ByteString, ByteString)
xmlAtt :: forall e. Parser e (ByteString, ByteString)
xmlAtt = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall e. Parser e ByteString
xmlName forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall e. Parser e ()
eq) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall e. Parser e ByteString
wrappedQ
openTag :: Parser Error (ByteString, [(ByteString, ByteString)])
openTag :: Parser Error (ByteString, [(ByteString, ByteString)])
openTag =
forall e. Parser e ()
lt forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e. Parser e ByteString
xmlName forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall e. Parser e ByteString
wss forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. Parser e (ByteString, ByteString)
xmlAtt) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wss) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall e. Parser e ()
gt forall a. Parser Error a -> Expected -> Parser Error a
`cut'` [Char] -> Expected
Msg [Char]
"open tag expected"
closeTag :: Parser Error ByteString
closeTag :: Parser Error ByteString
closeTag = forall e. Parser e ()
oct forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. Parser e ByteString
xmlName forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wss forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall e. Parser e ()
gt forall a. Parser Error a -> Expected -> Parser Error a
`cut'` [Char] -> Expected
Msg [Char]
"close tag expected"
emptyElemTag :: Parser Error (ByteString, [(ByteString, ByteString)])
emptyElemTag :: Parser Error (ByteString, [(ByteString, ByteString)])
emptyElemTag =
forall e. Parser e ()
lt forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e. Parser e ByteString
xmlName forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall e. Parser e ByteString
wss forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. Parser e (ByteString, ByteString)
xmlAtt) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wss) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall e. Parser e ()
gtc
xmlCommentOpen :: Parser e ()
= $(string "<!--")
xmlCommentClose :: Parser e ()
= $(string "-->")
xmlCharNotMinus :: Parser e ByteString
xmlCharNotMinus :: forall e. Parser e ByteString
xmlCharNotMinus = forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$ forall (st :: ZeroBitType) e. (Char -> Bool) -> ParserT st e Char
satisfy (forall a. Eq a => a -> a -> Bool
/= Char
'-')
xmlMinusPlusChar :: Parser e ByteString
xmlMinusPlusChar :: forall e. Parser e ByteString
xmlMinusPlusChar = forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$ $(char '-') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. Parser e ByteString
xmlCharNotMinus
xmlComment :: Parser e ByteString
= forall e. Parser e ()
xmlCommentOpen forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf (forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall e. Parser e ByteString
xmlCharNotMinus forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e a -> ParserT st e a
<|> forall e. Parser e ByteString
xmlMinusPlusChar)) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall e. Parser e ()
xmlCommentClose
xmlProlog :: Parser e ByteString
xmlProlog :: forall e. Parser e ByteString
xmlProlog =
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$
forall e. Parser e ByteString
xmlXMLDecl
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall e. Parser e XmlMisc
xmlMisc
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional (forall e. Parser e ByteString
xmlDoctypedecl forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e XmlMisc
xmlMisc)
xmlXMLDecl :: Parser e ByteString
xmlXMLDecl :: forall e. Parser e ByteString
xmlXMLDecl =
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$
$(string "<?xml")
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall e. Parser e ByteString
xmlVersionInfo
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
xmlEncodingDecl
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wssDDecl
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wss
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> $(string "?>")
xmlVersionInfo :: Parser e ByteString
xmlVersionInfo :: forall e. Parser e ByteString
xmlVersionInfo = forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$ forall e. Parser e ByteString
wss forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> $(string "version") forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall e. Parser e ()
eq forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall e a. Parser e a -> Parser e a
wrappedQNoGuard forall e. Parser e ByteString
xmlVersionNum
xmlVersionNum :: Parser e ByteString
xmlVersionNum :: forall e. Parser e ByteString
xmlVersionNum =
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf ($(string "1.") forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Alternative f => f a -> f [a]
some (forall (st :: ZeroBitType) e. (Char -> Bool) -> ParserT st e Char
satisfy Char -> Bool
isDigit))
data XmlMiscType = | XMiscS deriving (forall x. Rep XmlMiscType x -> XmlMiscType
forall x. XmlMiscType -> Rep XmlMiscType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep XmlMiscType x -> XmlMiscType
$cfrom :: forall x. XmlMiscType -> Rep XmlMiscType x
Generic, Int -> XmlMiscType -> ShowS
[XmlMiscType] -> ShowS
XmlMiscType -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [XmlMiscType] -> ShowS
$cshowList :: [XmlMiscType] -> ShowS
show :: XmlMiscType -> [Char]
$cshow :: XmlMiscType -> [Char]
showsPrec :: Int -> XmlMiscType -> ShowS
$cshowsPrec :: Int -> XmlMiscType -> ShowS
Show, XmlMiscType -> XmlMiscType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: XmlMiscType -> XmlMiscType -> Bool
$c/= :: XmlMiscType -> XmlMiscType -> Bool
== :: XmlMiscType -> XmlMiscType -> Bool
$c== :: XmlMiscType -> XmlMiscType -> Bool
Eq)
data XmlMisc = XmlMisc {XmlMisc -> XmlMiscType
xmiscType :: XmlMiscType, XmlMisc -> ByteString
xmiscContent :: ByteString} deriving (forall x. Rep XmlMisc x -> XmlMisc
forall x. XmlMisc -> Rep XmlMisc x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep XmlMisc x -> XmlMisc
$cfrom :: forall x. XmlMisc -> Rep XmlMisc x
Generic, Int -> XmlMisc -> ShowS
[XmlMisc] -> ShowS
XmlMisc -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [XmlMisc] -> ShowS
$cshowList :: [XmlMisc] -> ShowS
show :: XmlMisc -> [Char]
$cshow :: XmlMisc -> [Char]
showsPrec :: Int -> XmlMisc -> ShowS
$cshowsPrec :: Int -> XmlMisc -> ShowS
Show, XmlMisc -> XmlMisc -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: XmlMisc -> XmlMisc -> Bool
$c/= :: XmlMisc -> XmlMisc -> Bool
== :: XmlMisc -> XmlMisc -> Bool
$c== :: XmlMisc -> XmlMisc -> Bool
Eq)
xmlMisc :: Parser e XmlMisc
xmlMisc :: forall e. Parser e XmlMisc
xmlMisc =
(XmlMiscType -> ByteString -> XmlMisc
XmlMisc XmlMiscType
XMiscComment forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e. Parser e ByteString
xmlComment)
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e a -> ParserT st e a
<|> (XmlMiscType -> ByteString -> XmlMisc
XmlMisc XmlMiscType
XMiscS forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e. Parser e ByteString
wss)
exampleDocument :: ByteString
exampleDocument :: ByteString
exampleDocument =
[i|
<?xml version="1.0" standalone="yes" ?>
<!--open the DOCTYPE declaration -
the open square bracket indicates an internal DTD-->
<!DOCTYPE foo [
<!--define the internal DTD-->
<!ELEMENT foo (\#PCDATA)>
<!--close the DOCTYPE declaration-->
]>
<foo>Hello World.</foo>
|]
xmlDoctypedecl :: Parser e ByteString
xmlDoctypedecl :: forall e. Parser e ByteString
xmlDoctypedecl =
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$
$(string "<!DOCTYPE")
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall e. Parser e ByteString
wss
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall e. Parser e ByteString
xmlName
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wss
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e [Char]
bracketedSB
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e (Maybe a)
optional forall e. Parser e ByteString
wss
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> $(char '>')
bracketedSB :: Parser e [Char]
bracketedSB :: forall e. Parser e [Char]
bracketedSB = forall e b a. Parser e b -> Parser e b -> Parser e a -> Parser e a
bracketed $(char '[') $(char ']') (forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall (st :: ZeroBitType) e. (Char -> Bool) -> ParserT st e Char
satisfy (forall a. Eq a => a -> a -> Bool
/= Char
']')))
wssDDecl :: Parser e ByteString
wssDDecl :: forall e. Parser e ByteString
wssDDecl =
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$
forall e. Parser e ByteString
wss forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> $(string "standalone") forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. Parser e ()
eq forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. Parser e ByteString
xmlYesNo
xmlYesNo :: Parser e ByteString
xmlYesNo :: forall e. Parser e ByteString
xmlYesNo = forall e a. Parser e a -> Parser e a
wrappedQNoGuard (forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf forall a b. (a -> b) -> a -> b
$ $(string "yes") forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e a -> ParserT st e a
<|> $(string "no"))
xmlEncodingDecl :: Parser e ByteString
xmlEncodingDecl :: forall e. Parser e ByteString
xmlEncodingDecl = forall e. Parser e ByteString
wss forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> $(string "encoding") forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. Parser e ()
eq forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e a. Parser e a -> Parser e a
wrappedQNoGuard forall e. Parser e ByteString
xmlEncName
xmlEncName :: Parser e ByteString
xmlEncName :: forall e. Parser e ByteString
xmlEncName = forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf (forall (st :: ZeroBitType) e. (Char -> Bool) -> ParserT st e Char
satisfyAscii Char -> Bool
isLatinLetter forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall (st :: ZeroBitType) e. (Char -> Bool) -> ParserT st e Char
satisfyAscii (\Char
x -> Char -> Bool
isLatinLetter Char
x Bool -> Bool -> Bool
|| Char -> Bool
isDigit Char
x Bool -> Bool -> Bool
|| forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem Char
x ([Char]
"._-" :: [Char]))))
data XmlDocument = XmlDocument ByteString Markup [XmlMisc] deriving (Int -> XmlDocument -> ShowS
[XmlDocument] -> ShowS
XmlDocument -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [XmlDocument] -> ShowS
$cshowList :: [XmlDocument] -> ShowS
show :: XmlDocument -> [Char]
$cshow :: XmlDocument -> [Char]
showsPrec :: Int -> XmlDocument -> ShowS
$cshowsPrec :: Int -> XmlDocument -> ShowS
Show, XmlDocument -> XmlDocument -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: XmlDocument -> XmlDocument -> Bool
$c/= :: XmlDocument -> XmlDocument -> Bool
== :: XmlDocument -> XmlDocument -> Bool
$c== :: XmlDocument -> XmlDocument -> Bool
Eq)
xmlDocument :: Parser Error XmlDocument
xmlDocument :: Parser Error XmlDocument
xmlDocument = ByteString -> Markup -> [XmlMisc] -> XmlDocument
XmlDocument forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall e. Parser e ()
ws_ forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. Parser e ByteString
xmlProlog) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Error Markup
markupP forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall e. Parser e XmlMisc
xmlMisc
markupP :: Parser Error Markup
markupP :: Parser Error Markup
markupP =
((\(ByteString
n, [(ByteString, ByteString)]
as) -> ByteString -> Attributes -> [Content] -> Markup
Markup ByteString
n (forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ (ByteString, ByteString) -> Attributes
attribute forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(ByteString, ByteString)]
as) forall a. Monoid a => a
mempty) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Error (ByteString, [(ByteString, ByteString)])
emptyElemTag)
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e a -> ParserT st e a
<|>
((\(ByteString
n, [(ByteString, ByteString)]
as) [Content]
c ByteString
_ -> ByteString -> Attributes -> [Content] -> Markup
Markup ByteString
n (forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ (ByteString, ByteString) -> Attributes
attribute forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(ByteString, ByteString)]
as) [Content]
c) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Error (ByteString, [(ByteString, ByteString)])
openTag forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser Error Content
contentP forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Error ByteString
closeTag forall a. Parser Error a -> [Expected] -> Parser Error a
`cut` [Expected
"open tag", Expected
"content", Expected
"close tag"])
contentP :: Parser Error Content
contentP :: Parser Error Content
contentP =
(Markup -> Content
MarkupLeaf forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Error Markup
markupP)
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e a -> ParserT st e a
<|> (ByteString -> Content
Comment forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e. Parser e ByteString
xmlComment)
forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e a -> ParserT st e a
<|> (ByteString -> Content
Content forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (st :: ZeroBitType) e a.
ParserT st e a -> ParserT st e ByteString
byteStringOf (forall (f :: * -> *) a. Alternative f => f a -> f [a]
some (forall (st :: ZeroBitType) e. (Char -> Bool) -> ParserT st e Char
satisfy (forall a. Eq a => a -> a -> Bool
/= Char
'<'))))