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 = (a -> Either a b) -> ParsecT s u m a -> ParsecT s u m (Either a b)
forall a b. (a -> b) -> ParsecT s u m a -> ParsecT s u m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Either a b
forall a b. a -> Either a b
Left ParsecT s u m a
l ParsecT s u m (Either a b)
-> ParsecT s u m (Either a b) -> ParsecT s u m (Either a b)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
Parsec.<|> (b -> Either a b) -> ParsecT s u m b -> ParsecT s u m (Either a b)
forall a b. (a -> b) -> ParsecT s u m a -> ParsecT s u m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either a b
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 = a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
(NonEmpty.:|) (a -> [a] -> NonEmpty a)
-> ParsecT s u m a -> ParsecT s u m ([a] -> NonEmpty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT s u m a
p ParsecT s u m ([a] -> NonEmpty a)
-> ParsecT s u m [a] -> ParsecT s u m (NonEmpty a)
forall a b.
ParsecT s u m (a -> b) -> ParsecT s u m a -> ParsecT s u m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT s u m a -> ParsecT s u m [a]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
Parsec.many (ParsecT s u m sep
s ParsecT s u m sep -> ParsecT s u m a -> ParsecT s u m a
forall a b. ParsecT s u m a -> ParsecT s u m b -> ParsecT s u m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT s u m a
p)