{-# LANGUAGE OverloadedStrings #-}
module Text.ICalendar.Parser.Content where

import           Control.Applicative
import           Control.Monad
import           Data.ByteString.Lazy         (ByteString)
import qualified Data.ByteString.Builder      as Bu
import           Data.CaseInsensitive         (CI)
import           Data.Char
import           Data.Monoid
import           Data.Text.Lazy               (Text)

import qualified Text.Parsec                 as P
import           Text.Parsec.ByteString.Lazy ()
import           Text.Parsec.Combinator      hiding (optional)
import           Text.Parsec.Prim            hiding (many, (<|>))
import           Text.Parsec.Text.Lazy       ()

import Text.ICalendar.Parser.Common

parseToContent :: TextParser [Content]
parseToContent :: TextParser [Content]
parseToContent = do [Content]
content <- ParsecT ByteString DecodingFunctions Identity Content
-> ParsecT ByteString DecodingFunctions Identity ()
-> TextParser [Content]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepEndBy1 ParsecT ByteString DecodingFunctions Identity Content
contentline ParsecT ByteString DecodingFunctions Identity ()
newline
                    ByteString -> CI Text
f <- DecodingFunctions -> ByteString -> CI Text
dfBS2IText (DecodingFunctions -> ByteString -> CI Text)
-> ParsecT ByteString DecodingFunctions Identity DecodingFunctions
-> ParsecT
     ByteString DecodingFunctions Identity (ByteString -> CI Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT ByteString DecodingFunctions Identity DecodingFunctions
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
                    [Content] -> TextParser [Content]
forall a. a -> ParsecT ByteString DecodingFunctions Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Content] -> TextParser [Content])
-> [Content] -> TextParser [Content]
forall a b. (a -> b) -> a -> b
$ (ByteString -> CI Text) -> [Content] -> [Content]
componentalize ByteString -> CI Text
f [Content]
content

newline :: TextParser ()
newline :: ParsecT ByteString DecodingFunctions Identity ()
newline = (Char -> TextParser ByteString
char Char
'\r' TextParser ByteString
-> ParsecT ByteString DecodingFunctions Identity ()
-> ParsecT ByteString DecodingFunctions Identity ()
forall a b.
ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity b
-> ParsecT ByteString DecodingFunctions Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT ByteString DecodingFunctions Identity (Maybe ByteString)
-> ParsecT ByteString DecodingFunctions Identity ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (TextParser ByteString
-> ParsecT ByteString DecodingFunctions Identity (Maybe ByteString)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (TextParser ByteString
 -> ParsecT
      ByteString DecodingFunctions Identity (Maybe ByteString))
-> TextParser ByteString
-> ParsecT ByteString DecodingFunctions Identity (Maybe ByteString)
forall a b. (a -> b) -> a -> b
$ Char -> TextParser ByteString
char Char
'\n')) ParsecT ByteString DecodingFunctions Identity ()
-> ParsecT ByteString DecodingFunctions Identity ()
-> ParsecT ByteString DecodingFunctions Identity ()
forall a.
ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> TextParser ByteString
-> ParsecT ByteString DecodingFunctions Identity ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Char -> TextParser ByteString
char Char
'\n')


componentalize :: (ByteString -> CI Text) -> [Content] -> [Content]
componentalize :: (ByteString -> CI Text) -> [Content] -> [Content]
componentalize ByteString -> CI Text
f (ContentLine SourcePos
p CI Text
"BEGIN" [] ByteString
n:[Content]
xs) =
    let ([Content]
com, [Content]
rest) = (Content -> Bool) -> [Content] -> ([Content], [Content])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break Content -> Bool
g [Content]
xs
        g :: Content -> Bool
g (ContentLine SourcePos
_ CI Text
"END" [] ByteString
en) | ByteString -> CI Text
f ByteString
en CI Text -> CI Text -> Bool
forall a. Eq a => a -> a -> Bool
== CI Text
n' = Bool
True
        g Content
_ = Bool
False
        n' :: CI Text
n' = ByteString -> CI Text
f ByteString
n
     in SourcePos -> CI Text -> [Content] -> Content
Component SourcePos
p CI Text
n' ((ByteString -> CI Text) -> [Content] -> [Content]
componentalize ByteString -> CI Text
f [Content]
com)
                Content -> [Content] -> [Content]
forall a. a -> [a] -> [a]
: (ByteString -> CI Text) -> [Content] -> [Content]
componentalize ByteString -> CI Text
f (Int -> [Content] -> [Content]
forall a. Int -> [a] -> [a]
drop Int
1 [Content]
rest)
componentalize ByteString -> CI Text
f (Content
x:[Content]
xs) = Content
xContent -> [Content] -> [Content]
forall a. a -> [a] -> [a]
:(ByteString -> CI Text) -> [Content] -> [Content]
componentalize ByteString -> CI Text
f [Content]
xs
componentalize ByteString -> CI Text
_ [Content]
_ = []


-- | Specialized scan function which unfolds lines.
scan :: s -- ^ Initial state.
     -> (s -> Maybe Char -> Maybe (Maybe s))
     -- ^ Nothing: Fail.
     -- Just Nothing: Done, don't use last char.
     -- Just (Just state): Continue, collecting char unless EOF.
     -> TextParser ByteString
scan :: forall s.
s -> (s -> Maybe Char -> Maybe (Maybe s)) -> TextParser ByteString
scan s
state s -> Maybe Char -> Maybe (Maybe s)
f = s -> Builder -> TextParser ByteString
forall {u}.
s -> Builder -> ParsecT ByteString u Identity ByteString
go s
state Builder
forall a. Monoid a => a
mempty
  where go :: s -> Builder -> ParsecT ByteString u Identity ByteString
go s
st Builder
buf = do
            [Char]
_ <- ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity [Char]
forall a.
ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT ByteString u Identity Char
forall {u}. ParsecT ByteString u Identity Char
unfold)
            Maybe Char
c <- ParsecT ByteString u Identity (Maybe Char)
-> ParsecT ByteString u Identity (Maybe Char)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Char -> Maybe Char
forall a. a -> Maybe a
Just (Char -> Maybe Char)
-> ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity (Maybe Char)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT ByteString u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
P.anyChar ParsecT ByteString u Identity (Maybe Char)
-> ParsecT ByteString u Identity (Maybe Char)
-> ParsecT ByteString u Identity (Maybe Char)
forall a.
ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Char
forall a. Maybe a
Nothing Maybe Char
-> ParsecT ByteString u Identity ()
-> ParsecT ByteString u Identity (Maybe Char)
forall a b.
a
-> ParsecT ByteString u Identity b
-> ParsecT ByteString u Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT ByteString u Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
P.eof)
            case (Maybe Char
c, s -> Maybe Char -> Maybe (Maybe s)
f s
st Maybe Char
c) of
                 (Maybe Char
_, Maybe (Maybe s)
Nothing) -> ParsecT ByteString u Identity ByteString
forall a. ParsecT ByteString u Identity a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
                 (Just Char
c', Just (Just s
st')) ->
                    ParsecT ByteString u Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
P.anyChar ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity ByteString
-> ParsecT ByteString u Identity ByteString
forall a b.
ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity b
-> ParsecT ByteString u Identity b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> s -> Builder -> ParsecT ByteString u Identity ByteString
go s
st' (Builder
buf Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
Bu.char8 Char
c')
                 (Maybe Char
_, Maybe (Maybe s)
_) -> ByteString -> ParsecT ByteString u Identity ByteString
forall a. a -> ParsecT ByteString u Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> ParsecT ByteString u Identity ByteString)
-> ByteString -> ParsecT ByteString u Identity ByteString
forall a b. (a -> b) -> a -> b
$ Builder -> ByteString
Bu.toLazyByteString Builder
buf

        unfold :: ParsecT ByteString u Identity Char
unfold = (Char -> ParsecT ByteString u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
P.char Char
'\r' ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity (Maybe Char)
-> ParsecT ByteString u Identity (Maybe Char)
forall a b.
ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity b
-> ParsecT ByteString u Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> ParsecT ByteString u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
P.char Char
'\n') ParsecT ByteString u Identity (Maybe Char)
-> ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity Char
forall a b.
ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity b
-> ParsecT ByteString u Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> ParsecT ByteString u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
P.oneOf [Char]
" \t")
             ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity Char
forall a.
ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> ParsecT ByteString u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
P.char Char
'\n' ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity Char
-> ParsecT ByteString u Identity Char
forall a b.
ParsecT ByteString u Identity a
-> ParsecT ByteString u Identity b
-> ParsecT ByteString u Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> ParsecT ByteString u Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
P.oneOf [Char]
" \t")

takeWhile1 :: (Char -> Bool) -> TextParser ByteString
takeWhile1 :: (Char -> Bool) -> TextParser ByteString
takeWhile1 Char -> Bool
p = Bool
-> (Bool -> Maybe Char -> Maybe (Maybe Bool))
-> TextParser ByteString
forall s.
s -> (s -> Maybe Char -> Maybe (Maybe s)) -> TextParser ByteString
scan Bool
False Bool -> Maybe Char -> Maybe (Maybe Bool)
f TextParser ByteString -> [Char] -> TextParser ByteString
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"takeWhile1 ..."
  where f :: Bool -> Maybe Char -> Maybe (Maybe Bool)
f Bool
g (Just Char
x) | Char -> Bool
p Char
x       = Maybe Bool -> Maybe (Maybe Bool)
forall a. a -> Maybe a
Just (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True)
                     | Bool
g         = Maybe Bool -> Maybe (Maybe Bool)
forall a. a -> Maybe a
Just Maybe Bool
forall a. Maybe a
Nothing
                     | Bool
otherwise = Maybe (Maybe Bool)
forall a. Maybe a
Nothing
        f Bool
g Maybe Char
_        | Bool
g         = Maybe Bool -> Maybe (Maybe Bool)
forall a. a -> Maybe a
Just Maybe Bool
forall a. Maybe a
Nothing
                     | Bool
otherwise = Maybe (Maybe Bool)
forall a. Maybe a
Nothing

char :: Char -> TextParser ByteString
char :: Char -> TextParser ByteString
char Char
c = Bool
-> (Bool -> Maybe Char -> Maybe (Maybe Bool))
-> TextParser ByteString
forall s.
s -> (s -> Maybe Char -> Maybe (Maybe s)) -> TextParser ByteString
scan Bool
True Bool -> Maybe Char -> Maybe (Maybe Bool)
f TextParser ByteString -> [Char] -> TextParser ByteString
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> Char -> [Char]
forall a. Show a => a -> [Char]
show Char
c
  where f :: Bool -> Maybe Char -> Maybe (Maybe Bool)
f Bool
True Maybe Char
x = if Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c Maybe Char -> Maybe Char -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Char
x then Maybe Bool -> Maybe (Maybe Bool)
forall a. a -> Maybe a
Just (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False) else Maybe (Maybe Bool)
forall a. Maybe a
Nothing
        f Bool
False Maybe Char
_ = Maybe Bool -> Maybe (Maybe Bool)
forall a. a -> Maybe a
Just Maybe Bool
forall a. Maybe a
Nothing


isControl', isSafe, isValue, isQSafe, isName :: Char -> Bool
isControl' :: Char -> Bool
isControl' Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\t' Bool -> Bool -> Bool
&& Char -> Bool
isControl Char
c
isSafe :: Char -> Bool
isSafe Char
c = Bool -> Bool
not (Char -> Bool
isControl' Char
c) Bool -> Bool -> Bool
&& Char
c Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` ([Char]
"\";:,"::String)
isValue :: Char -> Bool
isValue Char
c = let n :: Int
n = Char -> Int
forall a. Enum a => a -> Int
fromEnum Char
c in Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
32 Bool -> Bool -> Bool
|| Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
9 Bool -> Bool -> Bool
|| (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0x21 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0x7F)
isQSafe :: Char -> Bool
isQSafe Char
c = Char -> Bool
isValue Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'"'
isName :: Char -> Bool
isName Char
c = Char -> Bool
isAsciiUpper Char
c Bool -> Bool -> Bool
|| Char -> Bool
isAsciiLower Char
c Bool -> Bool -> Bool
|| Char -> Bool
isDigit Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-'

contentline :: TextParser Content
contentline :: ParsecT ByteString DecodingFunctions Identity Content
contentline = do SourcePos
pos <- ParsecT ByteString DecodingFunctions Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
                 CI Text
n <- TextParser (CI Text)
name
                 [(CI Text, [Text])]
ps <- ParsecT ByteString DecodingFunctions Identity (CI Text, [Text])
-> ParsecT
     ByteString DecodingFunctions Identity [(CI Text, [Text])]
forall a.
ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Char -> TextParser ByteString
char Char
';' TextParser ByteString
-> ParsecT ByteString DecodingFunctions Identity (CI Text, [Text])
-> ParsecT ByteString DecodingFunctions Identity (CI Text, [Text])
forall a b.
ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity b
-> ParsecT ByteString DecodingFunctions Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT ByteString DecodingFunctions Identity (CI Text, [Text])
param)
                 ByteString
_ <- Char -> TextParser ByteString
char Char
':'
                 ByteString
val <- TextParser ByteString
value TextParser ByteString
-> TextParser ByteString -> TextParser ByteString
forall a.
ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ByteString -> TextParser ByteString
forall a. a -> ParsecT ByteString DecodingFunctions Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
forall a. Monoid a => a
mempty
                 Content -> ParsecT ByteString DecodingFunctions Identity Content
forall a. a -> ParsecT ByteString DecodingFunctions Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Content -> ParsecT ByteString DecodingFunctions Identity Content)
-> Content -> ParsecT ByteString DecodingFunctions Identity Content
forall a b. (a -> b) -> a -> b
$ SourcePos
-> CI Text -> [(CI Text, [Text])] -> ByteString -> Content
ContentLine SourcePos
pos CI Text
n [(CI Text, [Text])]
ps ByteString
val
  where value :: TextParser ByteString
        value :: TextParser ByteString
value = (Char -> Bool) -> TextParser ByteString
takeWhile1 Char -> Bool
isValue TextParser ByteString -> [Char] -> TextParser ByteString
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"value"

        param :: TextParser (CI Text, [Text])
        param :: ParsecT ByteString DecodingFunctions Identity (CI Text, [Text])
param = do CI Text
n <- TextParser (CI Text)
name
                   ByteString
_ <- Char -> TextParser ByteString
char Char
'='
                   [Text]
vs <- ParsecT ByteString DecodingFunctions Identity Text
-> TextParser ByteString
-> ParsecT ByteString DecodingFunctions Identity [Text]
forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
sepBy1 ParsecT ByteString DecodingFunctions Identity Text
paramValue (Char -> TextParser ByteString
char Char
',')
                   (CI Text, [Text])
-> ParsecT ByteString DecodingFunctions Identity (CI Text, [Text])
forall a. a -> ParsecT ByteString DecodingFunctions Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (CI Text
n, [Text]
vs)

        name :: TextParser (CI Text)
        name :: TextParser (CI Text)
name = DecodingFunctions -> ByteString -> CI Text
dfBS2IText (DecodingFunctions -> ByteString -> CI Text)
-> ParsecT ByteString DecodingFunctions Identity DecodingFunctions
-> ParsecT
     ByteString DecodingFunctions Identity (ByteString -> CI Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT ByteString DecodingFunctions Identity DecodingFunctions
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState ParsecT
  ByteString DecodingFunctions Identity (ByteString -> CI Text)
-> TextParser ByteString -> TextParser (CI Text)
forall a b.
ParsecT ByteString DecodingFunctions Identity (a -> b)
-> ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Bool) -> TextParser ByteString
takeWhile1 Char -> Bool
isName TextParser (CI Text) -> [Char] -> TextParser (CI Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"name"

        paramValue :: TextParser Text
        paramValue :: ParsecT ByteString DecodingFunctions Identity Text
paramValue = ParsecT ByteString DecodingFunctions Identity Text
paramtext ParsecT ByteString DecodingFunctions Identity Text
-> ParsecT ByteString DecodingFunctions Identity Text
-> ParsecT ByteString DecodingFunctions Identity Text
forall a.
ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT ByteString DecodingFunctions Identity Text
quotedString

        paramtext :: TextParser Text
        paramtext :: ParsecT ByteString DecodingFunctions Identity Text
paramtext = DecodingFunctions -> ByteString -> Text
dfBS2Text (DecodingFunctions -> ByteString -> Text)
-> ParsecT ByteString DecodingFunctions Identity DecodingFunctions
-> ParsecT
     ByteString DecodingFunctions Identity (ByteString -> Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT ByteString DecodingFunctions Identity DecodingFunctions
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState ParsecT ByteString DecodingFunctions Identity (ByteString -> Text)
-> TextParser ByteString
-> ParsecT ByteString DecodingFunctions Identity Text
forall a b.
ParsecT ByteString DecodingFunctions Identity (a -> b)
-> ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Char -> Bool) -> TextParser ByteString
takeWhile1 Char -> Bool
isSafe ParsecT ByteString DecodingFunctions Identity Text
-> [Char] -> ParsecT ByteString DecodingFunctions Identity Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"paramtext"

        quotedString :: TextParser Text
        quotedString :: ParsecT ByteString DecodingFunctions Identity Text
quotedString = (do
            ByteString
_ <- Char -> TextParser ByteString
char Char
'"'
            ByteString
s <- (Char -> Bool) -> TextParser ByteString
takeWhile1 Char -> Bool
isQSafe TextParser ByteString
-> TextParser ByteString -> TextParser ByteString
forall a.
ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ByteString -> TextParser ByteString
forall a. a -> ParsecT ByteString DecodingFunctions Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
forall a. Monoid a => a
mempty
            ByteString
_ <- Char -> TextParser ByteString
char Char
'"'
            DecodingFunctions -> ByteString -> Text
dfBS2Text (DecodingFunctions -> ByteString -> Text)
-> ParsecT ByteString DecodingFunctions Identity DecodingFunctions
-> ParsecT
     ByteString DecodingFunctions Identity (ByteString -> Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT ByteString DecodingFunctions Identity DecodingFunctions
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState ParsecT ByteString DecodingFunctions Identity (ByteString -> Text)
-> TextParser ByteString
-> ParsecT ByteString DecodingFunctions Identity Text
forall a b.
ParsecT ByteString DecodingFunctions Identity (a -> b)
-> ParsecT ByteString DecodingFunctions Identity a
-> ParsecT ByteString DecodingFunctions Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> TextParser ByteString
forall a. a -> ParsecT ByteString DecodingFunctions Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByteString
s) ParsecT ByteString DecodingFunctions Identity Text
-> [Char] -> ParsecT ByteString DecodingFunctions Identity Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"quoted string"