module Saturn.Unstable.Extra.Parsec where

import qualified Data.List.NonEmpty as NonEmpty
import qualified Text.Parsec as Parsec

either ::
  Parsec.ParsecT s u m a ->
  Parsec.ParsecT s u m b ->
  Parsec.ParsecT s u m (Either a b)
either :: forall s u (m :: * -> *) a b.
ParsecT s u m a -> ParsecT s u m b -> ParsecT s u m (Either a b)
either ParsecT s u m a
l ParsecT s u m b
r = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. a -> Either a b
Left ParsecT s u m a
l forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
Parsec.<|> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. b -> Either a b
Right ParsecT s u m b
r

sepByNE ::
  Parsec.ParsecT s u m a ->
  Parsec.ParsecT s u m sep ->
  Parsec.ParsecT s u m (NonEmpty.NonEmpty a)
sepByNE :: forall s u (m :: * -> *) a sep.
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m (NonEmpty a)
sepByNE ParsecT s u m a
p ParsecT s u m sep
s = forall a. a -> [a] -> NonEmpty a
(NonEmpty.:|) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT s u m a
p forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
Parsec.many (ParsecT s u m sep
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT s u m a
p)