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

import Control.Applicative.Combinators
import HeadedMegaparsec.Prelude hiding (body, head, try)
import Text.Megaparsec hiding (endBy1, sepBy1, sepEndBy1, some, someTill)
import Text.Megaparsec.Char
import qualified Text.Megaparsec.Char.Lexer as Lexer

contPossibly :: (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)) -> Parsec err strm a
contPossibly Parsec err strm (Either a (Parsec err strm a))
p = do
  Either a (Parsec err strm a)
junction <- Parsec err strm (Either a (Parsec err strm a))
-> Parsec err strm (Either a (Parsec err strm a))
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 -> a -> Parsec err strm a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
    Right Parsec err strm a
cont -> Parsec err strm a
cont