-- |
-- Extra megaparsec combinators.
module HeadedMegaparsec.Megaparsec where

import HeadedMegaparsec.Prelude hiding (head, try)
import Text.Megaparsec hiding (endBy1, sepBy1, sepEndBy1, some, someTill)

contPossibly :: (Ord err, Stream strm) => Parsec err strm (Either a (Parsec err strm a)) -> Parsec err strm a
contPossibly :: forall err strm a.
(Ord err, Stream strm) =>
Parsec err strm (Either a (Parsec err strm a)) -> Parsec err strm a
contPossibly Parsec err strm (Either a (Parsec err strm a))
p = do
  Either a (Parsec err strm a)
junction <- forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parsec err strm (Either a (Parsec err strm a))
p
  case Either a (Parsec err strm a)
junction of
    Left a
a -> forall (m :: * -> *) a. Monad m => a -> m a
return a
a
    Right Parsec err strm a
cont -> Parsec err strm a
cont