-- |
--
-- Module      :  Distribution.Deprecated.ReadP
-- Copyright   :  (c) The University of Glasgow 2002
-- License     :  BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer  :  libraries@haskell.org
-- Portability :  portable
--
-- Mostly re-exports of 'Text.ParserCombinators.ReadP', with added type synonym
-- 'Parser', and added functions 'skipSpaces1' and 'readP_to_E'.
module Distribution.Deprecated.ReadP
  ( -- * The 'ReadP' type
    T.ReadP

    -- * Primitive operations
  , T.get
  , T.look
  , (T.+++)
  , (T.<++)
  , T.gather

    -- * Other operations
  , T.pfail
  , T.eof
  , T.satisfy
  , T.char
  , T.string
  , T.munch
  , T.munch1
  , T.skipSpaces
  , skipSpaces1
  , T.choice
  , T.count
  , T.between
  , T.option
  , T.optional
  , T.many
  , T.many1
  , T.skipMany
  , T.skipMany1
  , T.sepBy
  , T.sepBy1
  , T.endBy
  , T.endBy1
  , T.chainr
  , T.chainl
  , T.chainl1
  , T.chainr1
  , T.manyTill

    -- * Running a parser
  , T.ReadS
  , T.readP_to_S
  , T.readS_to_P
  , readP_to_E

    -- ** Internal
  , Parser
  )
where

import Distribution.Client.Compat.Prelude
import Distribution.ReadE (ReadE (..))
import qualified Text.ParserCombinators.ReadP as T

type Parser = T.ReadP

skipSpaces1 :: T.ReadP ()
-- ^ Like 'skipSpaces' but succeeds only if there is at least one
-- whitespace character to skip.
skipSpaces1 :: ReadP ()
skipSpaces1 = (Char -> Bool) -> ReadP Char
T.satisfy Char -> Bool
isSpace ReadP Char -> ReadP () -> ReadP ()
forall a b. ReadP a -> ReadP b -> ReadP b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ReadP ()
T.skipSpaces

readP_to_E :: (String -> String) -> T.ReadP a -> ReadE a
readP_to_E :: forall a. (String -> String) -> ReadP a -> ReadE a
readP_to_E String -> String
err ReadP a
r =
  (String -> Either String a) -> ReadE a
forall a. (String -> Either String a) -> ReadE a
ReadE ((String -> Either String a) -> ReadE a)
-> (String -> Either String a) -> ReadE a
forall a b. (a -> b) -> a -> b
$ \String
txt -> case [ a
p | (a
p, String
s) <- ReadP a -> ReadS a
forall a. ReadP a -> ReadS a
T.readP_to_S ReadP a
r String
txt, (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace String
s
                       ] of
    [] -> String -> Either String a
forall a b. a -> Either a b
Left (String -> String
err String
txt)
    (a
p : [a]
_) -> a -> Either String a
forall a b. b -> Either a b
Right a
p