-- |
-- Module      : Streamly.Data.ParserK
-- Copyright   : (c) 2023 Composewell Technologies
-- License     : BSD-3-Clause
-- Maintainer  : streamly@composewell.com
-- Stability   : pre-release
-- Portability : GHC
--
-- Parsers using Continuation Passing Style (CPS). See notes in
-- "Streamly.Data.Parser" module to know when to use this module.
--
-- To run a 'ParserK' use 'Streamly.Data.StreamK.parseChunks'.
--
module Streamly.Data.ParserK
    (
    -- * Parser Type
      ParserK

    -- * Parsers
    -- ** Conversions
    , fromFold
    , fromParser
    -- , toParser

    -- ** Without Input
    , fromPure
    , fromEffect
    , die
    )

where

import Control.Monad.IO.Class (MonadIO)
import Streamly.Internal.Data.Fold (Fold)
import Streamly.Internal.Data.Unboxed (Unbox)
import qualified Streamly.Internal.Data.Parser.ParserD as ParserD

import Streamly.Internal.Data.Parser.ParserK.Type

-- | Convert a 'Fold' to a 'ParserK'.
--
{-# INLINE fromFold #-}
fromFold :: (MonadIO m, Unbox a) => Fold m a b -> ParserK a m b
fromFold :: forall (m :: * -> *) a b.
(MonadIO m, Unbox a) =>
Fold m a b -> ParserK a m b
fromFold = forall (m :: * -> *) a b.
(Monad m, Unbox a) =>
Parser a m b -> ParserK a m b
fromParser forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b. Monad m => Fold m a b -> Parser a m b
ParserD.fromFold