{-# LANGUAGE CPP #-}
module Ldap.Asn1.FromAsn1
( parseAsn1
, FromAsn1
) where
import Control.Applicative (Alternative(..), liftA2, optional)
import Control.Monad (MonadPlus(..), (>=>), guard)
import Data.ASN1.Types (ASN1)
import qualified Data.ASN1.Types as Asn1
import Data.Foldable (asum)
import Data.List.NonEmpty (some1)
import qualified Data.Text.Encoding as Text
import Ldap.Asn1.Type
{-# ANN module ("HLint: ignore Use const" :: String) #-}
{-# ANN module ("HLint: ignore Avoid lambda" :: String) #-}
parseAsn1 :: FromAsn1 a => [ASN1] -> Maybe ([ASN1], a)
parseAsn1 :: forall a. FromAsn1 a => [ASN1] -> Maybe ([ASN1], a)
parseAsn1 = forall s a. Parser s a -> s -> Maybe (s, a)
parse forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
class FromAsn1 a where
fromAsn1 :: Parser [ASN1] a
instance FromAsn1 op => FromAsn1 (LdapMessage op) where
fromAsn1 :: Parser [ASN1] (LdapMessage op)
fromAsn1 = do
Asn1.Start ASN1ConstructionType
Asn1.Sequence <- forall s. Parser [s] s
next
Id
i <- forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
op
op <- forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Asn1.End ASN1ConstructionType
Asn1.Sequence <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return (forall op. Id -> op -> Maybe Controls -> LdapMessage op
LdapMessage Id
i op
op forall a. Maybe a
Nothing)
instance FromAsn1 Id where
fromAsn1 :: Parser [ASN1] Id
fromAsn1 = do
Asn1.IntVal Integer
i <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return (Int32 -> Id
Id (forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i))
instance FromAsn1 LdapString where
fromAsn1 :: Parser [ASN1] LdapString
fromAsn1 = do
Asn1.OctetString ByteString
s <- forall s. Parser [s] s
next
case ByteString -> Either UnicodeException Text
Text.decodeUtf8' ByteString
s of
Right Text
t -> forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> LdapString
LdapString Text
t)
Left UnicodeException
_ -> forall (f :: * -> *) a. Alternative f => f a
empty
instance FromAsn1 LdapOid where
fromAsn1 :: Parser [ASN1] LdapOid
fromAsn1 = do
Asn1.OctetString ByteString
s <- forall s. Parser [s] s
next
case ByteString -> Either UnicodeException Text
Text.decodeUtf8' ByteString
s of
Right Text
t -> forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> LdapOid
LdapOid Text
t)
Left UnicodeException
_ -> forall (f :: * -> *) a. Alternative f => f a
empty
instance FromAsn1 LdapDn where
fromAsn1 :: Parser [ASN1] LdapDn
fromAsn1 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapString -> LdapDn
LdapDn forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
instance FromAsn1 AttributeDescription where
fromAsn1 :: Parser [ASN1] AttributeDescription
fromAsn1 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapString -> AttributeDescription
AttributeDescription forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
instance FromAsn1 AttributeValue where
fromAsn1 :: Parser [ASN1] AttributeValue
fromAsn1 = do
Asn1.OctetString ByteString
s <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> AttributeValue
AttributeValue ByteString
s)
instance FromAsn1 PartialAttribute where
fromAsn1 :: Parser [ASN1] PartialAttribute
fromAsn1 = do
Asn1.Start ASN1ConstructionType
Asn1.Sequence <- forall s. Parser [s] s
next
AttributeDescription
d <- forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Asn1.Start ASN1ConstructionType
Asn1.Set <- forall s. Parser [s] s
next
[AttributeValue]
vs <- forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Asn1.End ASN1ConstructionType
Asn1.Set <- forall s. Parser [s] s
next
Asn1.End ASN1ConstructionType
Asn1.Sequence <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return (AttributeDescription -> [AttributeValue] -> PartialAttribute
PartialAttribute AttributeDescription
d [AttributeValue]
vs)
instance FromAsn1 LdapResult where
fromAsn1 :: Parser [ASN1] LdapResult
fromAsn1 = do
ResultCode
resultCode <- do
Asn1.Enumerated Integer
x <- forall s. Parser [s] s
next
case Integer
x of
Integer
0 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
Success
Integer
1 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
OperationError
Integer
2 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
ProtocolError
Integer
3 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
TimeLimitExceeded
Integer
4 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
SizeLimitExceeded
Integer
5 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
CompareFalse
Integer
6 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
CompareTrue
Integer
7 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
AuthMethodNotSupported
Integer
8 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
StrongerAuthRequired
Integer
10 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
Referral
Integer
11 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
AdminLimitExceeded
Integer
12 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
UnavailableCriticalExtension
Integer
13 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
ConfidentialityRequired
Integer
14 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
SaslBindInProgress
Integer
16 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
NoSuchAttribute
Integer
17 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
UndefinedAttributeType
Integer
18 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
InappropriateMatching
Integer
19 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
ConstraintViolation
Integer
20 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
AttributeOrValueExists
Integer
21 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
InvalidAttributeSyntax
Integer
32 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
NoSuchObject
Integer
33 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
AliasProblem
Integer
34 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
InvalidDNSyntax
Integer
36 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
AliasDereferencingProblem
Integer
48 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
InappropriateAuthentication
Integer
49 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
InvalidCredentials
Integer
50 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
InsufficientAccessRights
Integer
51 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
Busy
Integer
52 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
Unavailable
Integer
53 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
UnwillingToPerform
Integer
54 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
LoopDetect
Integer
64 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
NamingViolation
Integer
65 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
ObjectClassViolation
Integer
66 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
NotAllowedOnNonLeaf
Integer
67 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
NotAllowedOnRDN
Integer
68 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
EntryAlreadyExists
Integer
69 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
ObjectClassModsProhibited
Integer
71 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
AffectsMultipleDSAs
Integer
80 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ResultCode
Other
Integer
_ -> forall (f :: * -> *) a. Alternative f => f a
empty
LdapDn
matchedDn <- forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
LdapString
diagnosticMessage
<- forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Maybe ReferralUris
referral <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall a b. (a -> b) -> a -> b
$ do
Asn1.Start (Asn1.Container ASN1Class
Asn1.Context ASN1Tag
0) <- forall s. Parser [s] s
next
ReferralUris
x <- forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Asn1.End (Asn1.Container ASN1Class
Asn1.Context ASN1Tag
0) <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return ReferralUris
x
forall (m :: * -> *) a. Monad m => a -> m a
return (ResultCode
-> LdapDn -> LdapString -> Maybe ReferralUris -> LdapResult
LdapResult ResultCode
resultCode LdapDn
matchedDn LdapString
diagnosticMessage Maybe ReferralUris
referral)
instance FromAsn1 ReferralUris where
fromAsn1 :: Parser [ASN1] ReferralUris
fromAsn1 = do
Asn1.Start ASN1ConstructionType
Asn1.Sequence <- forall s. Parser [s] s
next
NonEmpty Uri
xs <- forall (f :: * -> *) a. Alternative f => f a -> f (NonEmpty a)
some1 forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Asn1.End ASN1ConstructionType
Asn1.Sequence <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return (NonEmpty Uri -> ReferralUris
ReferralUris NonEmpty Uri
xs)
instance FromAsn1 Uri where
fromAsn1 :: Parser [ASN1] Uri
fromAsn1 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapString -> Uri
Uri forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
instance FromAsn1 ProtocolServerOp where
fromAsn1 :: Parser [ASN1] ProtocolServerOp
fromAsn1 = forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
[ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\LdapResult
res -> LdapResult -> Maybe ByteString -> ProtocolServerOp
BindResponse LdapResult
res forall a. Maybe a
Nothing) (forall {b}. FromAsn1 b => ASN1Tag -> Parser [ASN1] b
app ASN1Tag
1)
, forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry LdapDn -> PartialAttributeList -> ProtocolServerOp
SearchResultEntry) (forall {b}. FromAsn1 b => ASN1Tag -> Parser [ASN1] b
app ASN1Tag
4)
, forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapResult -> ProtocolServerOp
SearchResultDone (forall {b}. FromAsn1 b => ASN1Tag -> Parser [ASN1] b
app ASN1Tag
5)
, forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapResult -> ProtocolServerOp
ModifyResponse (forall {b}. FromAsn1 b => ASN1Tag -> Parser [ASN1] b
app ASN1Tag
7)
, forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapResult -> ProtocolServerOp
AddResponse (forall {b}. FromAsn1 b => ASN1Tag -> Parser [ASN1] b
app ASN1Tag
9)
, forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapResult -> ProtocolServerOp
DeleteResponse (forall {b}. FromAsn1 b => ASN1Tag -> Parser [ASN1] b
app ASN1Tag
11)
, forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapResult -> ProtocolServerOp
ModifyDnResponse (forall {b}. FromAsn1 b => ASN1Tag -> Parser [ASN1] b
app ASN1Tag
13)
, forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LdapResult -> ProtocolServerOp
CompareResponse (forall {b}. FromAsn1 b => ASN1Tag -> Parser [ASN1] b
app ASN1Tag
15)
, do
Asn1.Start (Asn1.Container ASN1Class
Asn1.Application ASN1Tag
19) <- forall s. Parser [s] s
next
NonEmpty Uri
uris <- forall (f :: * -> *) a. Alternative f => f a -> f (NonEmpty a)
some1 forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Asn1.End (Asn1.Container ASN1Class
Asn1.Application ASN1Tag
19) <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return (NonEmpty Uri -> ProtocolServerOp
SearchResultReference NonEmpty Uri
uris)
, do
Asn1.Start (Asn1.Container ASN1Class
Asn1.Application ASN1Tag
24) <- forall s. Parser [s] s
next
LdapResult
res <- forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Maybe ByteString
utf8Name <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall a b. (a -> b) -> a -> b
$ do
Asn1.Other ASN1Class
Asn1.Context ASN1Tag
10 ByteString
s <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
s
Maybe Text
name <- forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) (\ByteString
n -> case ByteString -> Either UnicodeException Text
Text.decodeUtf8' ByteString
n of
Left UnicodeException
_ -> forall (f :: * -> *) a. Alternative f => f a
empty
Right Text
name -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just Text
name)) Maybe ByteString
utf8Name
Maybe ByteString
value <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall a b. (a -> b) -> a -> b
$ do
Asn1.Other ASN1Class
Asn1.Context ASN1Tag
11 ByteString
s <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
s
Asn1.End (Asn1.Container ASN1Class
Asn1.Application ASN1Tag
24) <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return (LdapResult -> Maybe LdapOid -> Maybe ByteString -> ProtocolServerOp
ExtendedResponse LdapResult
res (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> LdapOid
LdapOid Maybe Text
name) Maybe ByteString
value)
, do
Asn1.Start (Asn1.Container ASN1Class
Asn1.Application ASN1Tag
25) <- forall s. Parser [s] s
next
Maybe LdapOid
name <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Maybe ByteString
value <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall a b. (a -> b) -> a -> b
$ do
Asn1.OctetString ByteString
s <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
s
Asn1.End (Asn1.Container ASN1Class
Asn1.Application ASN1Tag
25) <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe LdapOid -> Maybe ByteString -> ProtocolServerOp
IntermediateResponse Maybe LdapOid
name Maybe ByteString
value)
]
where
app :: ASN1Tag -> Parser [ASN1] b
app ASN1Tag
l = do
Asn1.Start (Asn1.Container ASN1Class
Asn1.Application ASN1Tag
x) <- forall s. Parser [s] s
next
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (ASN1Tag
x forall a. Eq a => a -> a -> Bool
== ASN1Tag
l)
b
res <- forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Asn1.End (Asn1.Container ASN1Class
Asn1.Application ASN1Tag
y) <- forall s. Parser [s] s
next
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (ASN1Tag
y forall a. Eq a => a -> a -> Bool
== ASN1Tag
l)
forall (m :: * -> *) a. Monad m => a -> m a
return b
res
instance FromAsn1 PartialAttributeList where
fromAsn1 :: Parser [ASN1] PartialAttributeList
fromAsn1 = do
Asn1.Start ASN1ConstructionType
Asn1.Sequence <- forall s. Parser [s] s
next
[PartialAttribute]
xs <- forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
Asn1.End ASN1ConstructionType
Asn1.Sequence <- forall s. Parser [s] s
next
forall (m :: * -> *) a. Monad m => a -> m a
return ([PartialAttribute] -> PartialAttributeList
PartialAttributeList [PartialAttribute]
xs)
instance (FromAsn1 a, FromAsn1 b) => FromAsn1 (a, b) where
fromAsn1 :: Parser [ASN1] (a, b)
fromAsn1 = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1 forall a. FromAsn1 a => Parser [ASN1] a
fromAsn1
newtype Parser s a = Parser { forall s a. Parser s a -> s -> Maybe (s, a)
unParser :: s -> Maybe (s, a) }
instance Functor (Parser s) where
fmap :: forall a b. (a -> b) -> Parser s a -> Parser s b
fmap a -> b
f (Parser s -> Maybe (s, a)
g) = forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Maybe (s, a)
g)
instance Applicative (Parser s) where
pure :: forall a. a -> Parser s a
pure a
x = forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (\s
s -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (s
s, a
x))
Parser s -> Maybe (s, a -> b)
mf <*> :: forall a b. Parser s (a -> b) -> Parser s a -> Parser s b
<*> Parser s -> Maybe (s, a)
mx = forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser forall a b. (a -> b) -> a -> b
$ \s
s -> do
(s
s', a -> b
f) <- s -> Maybe (s, a -> b)
mf s
s
(s
s'', a
x) <- s -> Maybe (s, a)
mx s
s'
forall (f :: * -> *) a. Applicative f => a -> f a
pure (s
s'', a -> b
f a
x)
instance Alternative (Parser s) where
empty :: forall a. Parser s a
empty = forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (\s
_ -> forall (f :: * -> *) a. Alternative f => f a
empty)
Parser s -> Maybe (s, a)
ma <|> :: forall a. Parser s a -> Parser s a -> Parser s a
<|> Parser s -> Maybe (s, a)
mb =
forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (\s
s -> s -> Maybe (s, a)
ma s
s forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> s -> Maybe (s, a)
mb s
s)
instance Monad (Parser s) where
return :: forall a. a -> Parser s a
return a
x = forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (\s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return (s
s, a
x))
Parser s -> Maybe (s, a)
mx >>= :: forall a b. Parser s a -> (a -> Parser s b) -> Parser s b
>>= a -> Parser s b
k =
forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (s -> Maybe (s, a)
mx forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \(s
s', a
x) -> forall s a. Parser s a -> s -> Maybe (s, a)
unParser (a -> Parser s b
k a
x) s
s')
instance MonadFail (Parser s) where
fail :: forall a. String -> Parser s a
fail String
_ = forall (f :: * -> *) a. Alternative f => f a
empty
instance MonadPlus (Parser s) where
mzero :: forall a. Parser s a
mzero = forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (\s
_ -> forall (m :: * -> *) a. MonadPlus m => m a
mzero)
Parser s -> Maybe (s, a)
ma mplus :: forall a. Parser s a -> Parser s a -> Parser s a
`mplus` Parser s -> Maybe (s, a)
mb =
forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (\s
s -> s -> Maybe (s, a)
ma s
s forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` s -> Maybe (s, a)
mb s
s)
parse :: Parser s a -> s -> Maybe (s, a)
parse :: forall s a. Parser s a -> s -> Maybe (s, a)
parse = forall s a. Parser s a -> s -> Maybe (s, a)
unParser
next :: Parser [s] s
next :: forall s. Parser [s] s
next = forall s a. (s -> Maybe (s, a)) -> Parser s a
Parser (\[s]
s -> case [s]
s of [] -> forall a. Maybe a
Nothing; s
x : [s]
xs -> forall a. a -> Maybe a
Just ([s]
xs, s
x))