{-# LANGUAGE CPP #-}
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}

-- | Working with human-friendly (as opposed to the compiler-friendly
--   'Show' and 'Read') textual representations.
module Data.Textual
  (
  -- * Printing
    Printable(..)
  , maybePrint
  , toString
  , toText
  , toLazyText
  , toAscii
  , toLazyAscii
  , toUtf8
  , toLazyUtf8
  -- * Parsing
  , Textual(..)
  -- ** Built-in parser
  , Parsed(..)
  , isParsed
  , isMalformed
  , maybeParsed
  , builtInParser
  , parseString
  , parseStringAs
  , parseText
  , parseTextAs
  , parseLazyText
  , parseLazyTextAs
  , parseAscii
  , parseAsciiAs
  , parseLazyAscii
  , parseLazyAsciiAs
  , parseUtf8
  , parseUtf8As
  , parseLazyUtf8
  , parseLazyUtf8As
  , fromString
  , fromStringAs
  , fromText
  , fromTextAs
  , fromLazyText
  , fromLazyTextAs
  , fromAscii
  , fromAsciiAs
  , fromLazyAscii
  , fromLazyAsciiAs
  , fromUtf8
  , fromUtf8As
  , fromLazyUtf8
  , fromLazyUtf8As
  ) where

import Prelude hiding (print)
import Data.Typeable (Typeable)
import Data.Foldable (Foldable)
import Data.Traversable (Traversable)
import Data.Monoid (mempty)
import Data.Int
import Data.Word
import Data.Ratio (Ratio)
import Data.Fixed (Fixed, HasResolution)
import Data.List (stripPrefix)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Lazy.Char8 as BL8
import qualified Data.Text as TS
import qualified Data.Text.Lazy as TL
import Data.Text.Lazy.Encoding (decodeUtf8)
import Data.Textual.Integral
import Data.Textual.Fractional
import Control.Applicative
import qualified Text.Printer as TP
import qualified Text.Printer.Integral as TP
import qualified Text.Printer.Fractional as TP
import Text.Parser.Combinators (Parsing, (<?>))
import qualified Text.Parser.Combinators as PC
import Text.Parser.Char (CharParsing)
import qualified Text.Parser.Char as PC

-- | The default printer for values of a type.
class Printable α where
  print  TP.Printer p  α  p

instance Printable Char where
  print :: forall p. Printer p => Char -> p
print = Char -> p
forall p. Printer p => Char -> p
TP.char
  {-# INLINE print #-}

instance Printable String where
  print :: forall p. Printer p => String -> p
print = String -> p
forall p. Printer p => String -> p
TP.string
  {-# INLINE print #-}

instance Printable TS.Text where
  print :: forall p. Printer p => Text -> p
print = Text -> p
forall p. Printer p => Text -> p
TP.text
  {-# INLINE print #-}

instance Printable TL.Text where
  print :: forall p. Printer p => Text -> p
print = Text -> p
forall p. Printer p => Text -> p
TP.lazyText
  {-# INLINE print #-}

instance Printable Integer where
  print :: forall p. Printer p => Integer -> p
print = Integer -> p
forall α p. (Integral α, Printer p) => α -> p
TP.decimal
  {-# INLINE print #-}

instance Printable Int where
  print :: forall p. Printer p => Int -> p
print = Int -> p
forall α p. (Integral α, Printer p) => α -> p
TP.decimal
  {-# INLINE print #-}

instance Printable Int8 where
  print :: forall p. Printer p => Int8 -> p
print = Int8 -> p
forall α p. (Integral α, Printer p) => α -> p
TP.decimal
  {-# INLINE print #-}

instance Printable Int16 where
  print :: forall p. Printer p => Int16 -> p
print = Int16 -> p
forall α p. (Integral α, Printer p) => α -> p
TP.decimal
  {-# INLINE print #-}

instance Printable Int32 where
  print :: forall p. Printer p => Int32 -> p
print = Int32 -> p
forall α p. (Integral α, Printer p) => α -> p
TP.decimal
  {-# INLINE print #-}

instance Printable Int64 where
  print :: forall p. Printer p => Int64 -> p
print = Int64 -> p
forall α p. (Integral α, Printer p) => α -> p
TP.decimal
  {-# INLINE print #-}

instance Printable Word where
  print :: forall p. Printer p => Word -> p
print = Word -> p
forall α p. (Integral α, Printer p) => α -> p
TP.nnDecimal
  {-# INLINE print #-}

instance Printable Word8 where
  print :: forall p. Printer p => Word8 -> p
print = Word8 -> p
forall α p. (Integral α, Printer p) => α -> p
TP.nnDecimal
  {-# INLINE print #-}

instance Printable Word16 where
  print :: forall p. Printer p => Word16 -> p
print = Word16 -> p
forall α p. (Integral α, Printer p) => α -> p
TP.nnDecimal
  {-# INLINE print #-}

instance Printable Word32 where
  print :: forall p. Printer p => Word32 -> p
print = Word32 -> p
forall α p. (Integral α, Printer p) => α -> p
TP.nnDecimal
  {-# INLINE print #-}

instance Printable Word64 where
  print :: forall p. Printer p => Word64 -> p
print = Word64 -> p
forall α p. (Integral α, Printer p) => α -> p
TP.nnDecimal
  {-# INLINE print #-}

instance Integral α  Printable (Ratio α) where
  print :: forall p. Printer p => Ratio α -> p
print = Ratio α -> p
forall α p. (Real α, Printer p) => α -> p
TP.fraction
  {-# INLINE print #-}

instance HasResolution α  Printable (Fixed α) where
  print :: forall p. Printer p => Fixed α -> p
print = String -> p
forall p. Printer p => String -> p
TP.string7 (String -> p) -> (Fixed α -> String) -> Fixed α -> p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed α -> String
forall a. Show a => a -> String
show
  {-# INLINE print #-}

instance Printable Float where
  print :: forall p. Printer p => Float -> p
print = String -> p
forall p. Printer p => String -> p
TP.string7 (String -> p) -> (Float -> String) -> Float -> p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> String
forall a. Show a => a -> String
show
  {-# INLINE print #-}

instance Printable Double where
  print :: forall p. Printer p => Double -> p
print = String -> p
forall p. Printer p => String -> p
TP.string7 (String -> p) -> (Double -> String) -> Double -> p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> String
forall a. Show a => a -> String
show
  {-# INLINE print #-}

-- | A shorthand for @'maybe' 'mempty' 'print'@.
maybePrint  (TP.Printer p, Printable α)  Maybe α  p
maybePrint :: forall p α. (Printer p, Printable α) => Maybe α -> p
maybePrint = p -> (α -> p) -> Maybe α -> p
forall b a. b -> (a -> b) -> Maybe a -> b
maybe p
forall a. Monoid a => a
mempty α -> p
forall p. Printer p => α -> p
forall α p. (Printable α, Printer p) => α -> p
print
{-# INLINE maybePrint #-}

-- | A shorthand for @'TP.buildString' . 'print'@.
toString  Printable α  α  String
toString :: forall α. Printable α => α -> String
toString = StringBuilder -> String
TP.buildString (StringBuilder -> String) -> (α -> StringBuilder) -> α -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> StringBuilder
forall p. Printer p => α -> p
forall α p. (Printable α, Printer p) => α -> p
print
{-# INLINE[1] toString #-}

-- | A shorthand for @'TP.buildText' . 'print'@.
toText  Printable α  α  TS.Text
toText :: forall α. Printable α => α -> Text
toText = Builder -> Text
TP.buildText (Builder -> Text) -> (α -> Builder) -> α -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> Builder
forall p. Printer p => α -> p
forall α p. (Printable α, Printer p) => α -> p
print
{-# INLINE[1] toText #-}

-- | A shorthand for @'TP.buildLazyText' . 'print'@.
toLazyText  Printable α  α  TL.Text
toLazyText :: forall α. Printable α => α -> Text
toLazyText = Builder -> Text
TP.buildLazyText (Builder -> Text) -> (α -> Builder) -> α -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> Builder
forall p. Printer p => α -> p
forall α p. (Printable α, Printer p) => α -> p
print
{-# INLINE[1] toLazyText #-}

-- | A shorthand for @'TP.buildAscii' . 'print'@.
toAscii  Printable α  α  BS.ByteString
toAscii :: forall α. Printable α => α -> ByteString
toAscii = AsciiBuilder -> ByteString
TP.buildAscii (AsciiBuilder -> ByteString)
-> (α -> AsciiBuilder) -> α -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> AsciiBuilder
forall p. Printer p => α -> p
forall α p. (Printable α, Printer p) => α -> p
print
{-# INLINE[1] toAscii #-}

-- | A shorthand for @'TP.buildLazyAscii' . 'print'@.
toLazyAscii  Printable α  α  BL.ByteString
toLazyAscii :: forall α. Printable α => α -> ByteString
toLazyAscii = AsciiBuilder -> ByteString
TP.buildLazyAscii (AsciiBuilder -> ByteString)
-> (α -> AsciiBuilder) -> α -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> AsciiBuilder
forall p. Printer p => α -> p
forall α p. (Printable α, Printer p) => α -> p
print
{-# INLINE[1] toLazyAscii #-}

-- | A shorthand for @'TP.buildUtf8' . 'print'@.
toUtf8  Printable α  α  BS.ByteString
toUtf8 :: forall α. Printable α => α -> ByteString
toUtf8 = Utf8Builder -> ByteString
TP.buildUtf8 (Utf8Builder -> ByteString)
-> (α -> Utf8Builder) -> α -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> Utf8Builder
forall p. Printer p => α -> p
forall α p. (Printable α, Printer p) => α -> p
print
{-# INLINE[1] toUtf8 #-}

-- | A shorthand for @'TP.buildLazyUtf8' . 'print'@.
toLazyUtf8  Printable α  α  BL.ByteString
toLazyUtf8 :: forall α. Printable α => α -> ByteString
toLazyUtf8 = Utf8Builder -> ByteString
TP.buildLazyUtf8 (Utf8Builder -> ByteString)
-> (α -> Utf8Builder) -> α -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> Utf8Builder
forall p. Printer p => α -> p
forall α p. (Printable α, Printer p) => α -> p
print
{-# INLINE[1] toLazyUtf8 #-}

-- | The default parser for values of a type, must satisfy
--   @
--     'fromString' ('toString' /x/) = 'Just' /x/
--   @
class Printable α  Textual α where
  textual  (Monad μ, CharParsing μ)  μ α

instance Textual Char where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Char
textual = μ Char
forall (m :: * -> *). CharParsing m => m Char
PC.anyChar
  {-# INLINE textual #-}

instance Textual Integer where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Integer
textual = Decimal -> μ Integer
forall s α (μ :: * -> *).
(PositionalSystem s, Num α, Monad μ, CharParsing μ) =>
s -> μ α
number Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Int where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Int
textual = Decimal -> μ Int
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
bounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Int8 where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Int8
textual = Decimal -> μ Int8
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
bounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Int16 where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Int16
textual = Decimal -> μ Int16
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
bounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Int32 where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Int32
textual = Decimal -> μ Int32
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
bounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Int64 where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Int64
textual = Decimal -> μ Int64
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
bounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Word where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Word
textual = Decimal -> μ Word
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
nnBounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Word8 where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Word8
textual = Decimal -> μ Word8
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
nnBounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Word16 where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Word16
textual = Decimal -> μ Word16
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
nnBounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Word32 where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Word32
textual = Decimal -> μ Word32
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
nnBounded Decimal
Decimal
  {-# INLINE textual #-}

instance Textual Word64 where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ Word64
textual = Decimal -> μ Word64
forall s α (μ :: * -> *).
(PositionalSystem s, Ord α, Bounded α, Integral α, Monad μ,
 CharParsing μ) =>
s -> μ α
nnBounded Decimal
Decimal
  {-# INLINE textual #-}

instance Integral α  Textual (Ratio α) where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ (Ratio α)
textual = μ (Ratio α)
forall α (μ :: * -> *).
(Fractional α, Monad μ, CharParsing μ) =>
μ α
fraction
  {-# INLINE textual #-}

instance HasResolution α  Textual (Fixed α) where
  textual :: forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ (Fixed α)
textual = μ (Fixed α)
forall (μ :: * -> *) α.
(Monad μ, Fractional α, CharParsing μ) =>
μ α
fractional
  {-# INLINE textual #-}

-- | Parsing result.
data Parsed α = Parsed α
              | Malformed [String] String
              deriving (Typeable, (forall a b. (a -> b) -> Parsed a -> Parsed b)
-> (forall a b. a -> Parsed b -> Parsed a) -> Functor Parsed
forall a b. a -> Parsed b -> Parsed a
forall a b. (a -> b) -> Parsed a -> Parsed b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Parsed a -> Parsed b
fmap :: forall a b. (a -> b) -> Parsed a -> Parsed b
$c<$ :: forall a b. a -> Parsed b -> Parsed a
<$ :: forall a b. a -> Parsed b -> Parsed a
Functor, (forall m. Monoid m => Parsed m -> m)
-> (forall m a. Monoid m => (a -> m) -> Parsed a -> m)
-> (forall m a. Monoid m => (a -> m) -> Parsed a -> m)
-> (forall a b. (a -> b -> b) -> b -> Parsed a -> b)
-> (forall a b. (a -> b -> b) -> b -> Parsed a -> b)
-> (forall b a. (b -> a -> b) -> b -> Parsed a -> b)
-> (forall b a. (b -> a -> b) -> b -> Parsed a -> b)
-> (forall a. (a -> a -> a) -> Parsed a -> a)
-> (forall a. (a -> a -> a) -> Parsed a -> a)
-> (forall a. Parsed a -> [a])
-> (forall a. Parsed a -> Bool)
-> (forall a. Parsed a -> Int)
-> (forall a. Eq a => a -> Parsed a -> Bool)
-> (forall a. Ord a => Parsed a -> a)
-> (forall a. Ord a => Parsed a -> a)
-> (forall a. Num a => Parsed a -> a)
-> (forall a. Num a => Parsed a -> a)
-> Foldable Parsed
forall a. Eq a => a -> Parsed a -> Bool
forall a. Num a => Parsed a -> a
forall a. Ord a => Parsed a -> a
forall m. Monoid m => Parsed m -> m
forall a. Parsed a -> Bool
forall a. Parsed a -> Int
forall a. Parsed a -> [a]
forall a. (a -> a -> a) -> Parsed a -> a
forall m a. Monoid m => (a -> m) -> Parsed a -> m
forall b a. (b -> a -> b) -> b -> Parsed a -> b
forall a b. (a -> b -> b) -> b -> Parsed a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Parsed m -> m
fold :: forall m. Monoid m => Parsed m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Parsed a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Parsed a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Parsed a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Parsed a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Parsed a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Parsed a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Parsed a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Parsed a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Parsed a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Parsed a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Parsed a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Parsed a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Parsed a -> a
foldr1 :: forall a. (a -> a -> a) -> Parsed a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Parsed a -> a
foldl1 :: forall a. (a -> a -> a) -> Parsed a -> a
$ctoList :: forall a. Parsed a -> [a]
toList :: forall a. Parsed a -> [a]
$cnull :: forall a. Parsed a -> Bool
null :: forall a. Parsed a -> Bool
$clength :: forall a. Parsed a -> Int
length :: forall a. Parsed a -> Int
$celem :: forall a. Eq a => a -> Parsed a -> Bool
elem :: forall a. Eq a => a -> Parsed a -> Bool
$cmaximum :: forall a. Ord a => Parsed a -> a
maximum :: forall a. Ord a => Parsed a -> a
$cminimum :: forall a. Ord a => Parsed a -> a
minimum :: forall a. Ord a => Parsed a -> a
$csum :: forall a. Num a => Parsed a -> a
sum :: forall a. Num a => Parsed a -> a
$cproduct :: forall a. Num a => Parsed a -> a
product :: forall a. Num a => Parsed a -> a
Foldable, Functor Parsed
Foldable Parsed
(Functor Parsed, Foldable Parsed) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Parsed a -> f (Parsed b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Parsed (f a) -> f (Parsed a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Parsed a -> m (Parsed b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Parsed (m a) -> m (Parsed a))
-> Traversable Parsed
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Parsed (m a) -> m (Parsed a)
forall (f :: * -> *) a.
Applicative f =>
Parsed (f a) -> f (Parsed a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Parsed a -> m (Parsed b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Parsed a -> f (Parsed b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Parsed a -> f (Parsed b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Parsed a -> f (Parsed b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Parsed (f a) -> f (Parsed a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Parsed (f a) -> f (Parsed a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Parsed a -> m (Parsed b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Parsed a -> m (Parsed b)
$csequence :: forall (m :: * -> *) a. Monad m => Parsed (m a) -> m (Parsed a)
sequence :: forall (m :: * -> *) a. Monad m => Parsed (m a) -> m (Parsed a)
Traversable, Parsed α -> Parsed α -> Bool
(Parsed α -> Parsed α -> Bool)
-> (Parsed α -> Parsed α -> Bool) -> Eq (Parsed α)
forall α. Eq α => Parsed α -> Parsed α -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall α. Eq α => Parsed α -> Parsed α -> Bool
== :: Parsed α -> Parsed α -> Bool
$c/= :: forall α. Eq α => Parsed α -> Parsed α -> Bool
/= :: Parsed α -> Parsed α -> Bool
Eq, Int -> Parsed α -> ShowS
[Parsed α] -> ShowS
Parsed α -> String
(Int -> Parsed α -> ShowS)
-> (Parsed α -> String) -> ([Parsed α] -> ShowS) -> Show (Parsed α)
forall α. Show α => Int -> Parsed α -> ShowS
forall α. Show α => [Parsed α] -> ShowS
forall α. Show α => Parsed α -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall α. Show α => Int -> Parsed α -> ShowS
showsPrec :: Int -> Parsed α -> ShowS
$cshow :: forall α. Show α => Parsed α -> String
show :: Parsed α -> String
$cshowList :: forall α. Show α => [Parsed α] -> ShowS
showList :: [Parsed α] -> ShowS
Show)

instance Applicative Parsed where
  pure :: forall a. a -> Parsed a
pure = a -> Parsed a
forall a. a -> Parsed a
Parsed
  {-# INLINE pure #-}
  Parsed a -> b
f       <*> :: forall a b. Parsed (a -> b) -> Parsed a -> Parsed b
<*> Parsed a
a       = b -> Parsed b
forall a. a -> Parsed a
Parsed (a -> b
f a
a)
  Malformed [String]
ls String
e <*> Parsed a
_              = [String] -> String -> Parsed b
forall α. [String] -> String -> Parsed α
Malformed [String]
ls String
e
  Parsed (a -> b)
_              <*> Malformed [String]
ls String
e = [String] -> String -> Parsed b
forall α. [String] -> String -> Parsed α
Malformed [String]
ls String
e
  {-# INLINABLE (<*>) #-}

instance Alternative Parsed where
  empty :: forall a. Parsed a
empty = [String] -> String -> Parsed a
forall α. [String] -> String -> Parsed α
Malformed [] String
"Alternative.empty"
  {-# INLINE empty #-}
  p :: Parsed a
p@(Parsed a
_) <|> :: forall a. Parsed a -> Parsed a -> Parsed a
<|> Parsed a
_ = Parsed a
p
  Parsed a
_            <|> Parsed a
p = Parsed a
p
  {-# INLINABLE (<|>) #-}

-- | Map 'Parsed' to 'True' and 'Malformed' to 'False'.
isParsed  Parsed α  Bool
isParsed :: forall a. Parsed a -> Bool
isParsed (Parsed α
_) = Bool
True
isParsed Parsed α
_          = Bool
False

-- | Map 'Parsed' to 'False' and 'Malformed' to 'True'.
isMalformed  Parsed α  Bool
isMalformed :: forall a. Parsed a -> Bool
isMalformed (Malformed [String]
_ String
_) = Bool
True
isMalformed Parsed α
_               = Bool
False

-- | Map 'Parsed' values to 'Just' and 'Malformed' to 'Nothing'.
maybeParsed  Parsed α  Maybe α
maybeParsed :: forall α. Parsed α -> Maybe α
maybeParsed (Parsed α
a) = α -> Maybe α
forall a. a -> Maybe a
Just α
a
maybeParsed Parsed α
_          = Maybe α
forall a. Maybe a
Nothing
{-# INLINABLE maybeParsed #-}

data Parser α =
  Parser { forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser   r
                     . [String]  Word  String
                      ([String]  Word  String  α  Parsed r)
                      ([String]  Word  String  String  Parsed r)
                      Parsed r }

instance Functor Parser where
  fmap :: forall a b. (a -> b) -> Parser a -> Parser b
fmap a -> b
f Parser a
p = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> b -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser b
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> b -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser b)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> b -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser b
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> b -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
               Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p [String]
ls Word
n String
i (\[String]
ls' Word
n' String
i' a
a  [String] -> Word -> String -> b -> Parsed r
c [String]
ls' Word
n' String
i' (a -> b
f a
a)) [String] -> Word -> String -> String -> Parsed r
h
  {-# INLINE fmap #-}

instance Applicative Parser where
  pure :: forall a. a -> Parser a
pure a
a = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> a -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser a
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> a -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser a)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> a -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser a
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> a -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
_  [String] -> Word -> String -> a -> Parsed r
c [String]
ls Word
n String
i a
a
  {-# INLINE pure #-}
  Parser (a -> b)
p <*> :: forall a b. Parser (a -> b) -> Parser a -> Parser b
<*> Parser a
p' = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> b -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser b
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> b -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser b)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> b -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser b
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> b -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
               Parser (a -> b)
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> (a -> b) -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser (a -> b)
p [String]
ls Word
n String
i 
                 (\[String]
ls' Word
n' String
i' a -> b
f 
                    Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p' [String]
ls' Word
n' String
i'
                      (\[String]
ls'' Word
n'' String
i'' a
a  [String] -> Word -> String -> b -> Parsed r
c [String]
ls'' Word
n'' String
i'' (a -> b
f a
a)) [String] -> Word -> String -> String -> Parsed r
h)
                 [String] -> Word -> String -> String -> Parsed r
h
  {-# INLINE (<*>) #-}
  Parser a
p *> :: forall a b. Parser a -> Parser b -> Parser b
*> Parser b
p' = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> b -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser b
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> b -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser b)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> b -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser b
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> b -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
              Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p [String]
ls Word
n String
i (\[String]
ls' Word
n' String
i' a
_  Parser b
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> b -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser b
p' [String]
ls' Word
n' String
i' [String] -> Word -> String -> b -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h) [String] -> Word -> String -> String -> Parsed r
h
  {-# INLINE (*>) #-}
  Parser a
p <* :: forall a b. Parser a -> Parser b -> Parser a
<* Parser b
p' = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> a -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser a
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> a -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser a)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> a -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser a
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> a -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
              Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p [String]
ls Word
n String
i
                        (\[String]
ls' Word
n' String
i' a
a 
                           Parser b
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> b -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser b
p' [String]
ls' Word
n' String
i'
                                     (\[String]
ls'' Word
n'' String
i'' b
_  [String] -> Word -> String -> a -> Parsed r
c [String]
ls'' Word
n'' String
i'' a
a) [String] -> Word -> String -> String -> Parsed r
h)
                        [String] -> Word -> String -> String -> Parsed r
h
  {-# INLINE (<*) #-}

instance Alternative Parser where
  empty :: forall a. Parser a
empty = String -> Parser a
forall a. String -> Parser a
forall (m :: * -> *) a. Parsing m => String -> m a
PC.unexpected String
"Alternative.empty"
  {-# INLINE empty #-}
  Parser a
p <|> :: forall a. Parser a -> Parser a -> Parser a
<|> Parser a
p' = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> a -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser a
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> a -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser a)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> a -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser a
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> a -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
               Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p [String]
ls Word
n String
i [String] -> Word -> String -> a -> Parsed r
c (([String] -> Word -> String -> String -> Parsed r) -> Parsed r)
-> ([String] -> Word -> String -> String -> Parsed r) -> Parsed r
forall a b. (a -> b) -> a -> b
$ \[String]
ls' Word
n' String
i' String
e  
                 if Word
n' Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
== Word
n then Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p' [String]
ls Word
n' String
i' [String] -> Word -> String -> a -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h
                            else [String] -> Word -> String -> String -> Parsed r
h [String]
ls' Word
n' String
i' String
e
  {-# INLINE (<|>) #-}

instance Parsing Parser where
  try :: forall a. Parser a -> Parser a
try Parser a
p = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> a -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser a
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> a -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser a)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> a -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser a
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> a -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
            Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p [String]
ls Word
n String
i [String] -> Word -> String -> a -> Parsed r
c (\[String]
ls' Word
_ String
_ String
e  [String] -> Word -> String -> String -> Parsed r
h [String]
ls' Word
n String
i String
e)
  {-# INLINE try #-}
  Parser a
p <?> :: forall a. Parser a -> String -> Parser a
<?> String
l = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> a -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser a
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> a -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser a)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> a -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser a
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> a -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
              Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p (String
l String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
ls) Word
n String
i (\[String]
_ Word
n' String
i' a
a  [String] -> Word -> String -> a -> Parsed r
c [String]
ls Word
n' String
i' a
a) [String] -> Word -> String -> String -> Parsed r
h
  {-# INLINE (<?>) #-}
  skipMany :: forall a. Parser a -> Parser ()
skipMany Parser a
p = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> () -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser ()
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> () -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser ())
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> () -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser ()
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> () -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
                 Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p [String]
ls Word
n String
i
                   (\[String]
ls' Word
n' String
i' a
_  Parser ()
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> () -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser (Parser a -> Parser ()
forall a. Parser a -> Parser ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
PC.skipMany Parser a
p) [String]
ls' Word
n' String
i' [String] -> Word -> String -> () -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h)
                   (\[String]
ls' Word
n' String
i' String
_  [String] -> Word -> String -> () -> Parsed r
c [String]
ls' Word
n' String
i' ())
  skipSome :: forall a. Parser a -> Parser ()
skipSome Parser a
p = Parser a
p Parser a -> Parser () -> Parser ()
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser a -> Parser ()
forall a. Parser a -> Parser ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
PC.skipMany Parser a
p
  {-# INLINE skipSome #-}
  unexpected :: forall a. String -> Parser a
unexpected String
e = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> a -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser a
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> a -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser a)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> a -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser a
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> a -> Parsed r
_ [String] -> Word -> String -> String -> Parsed r
h  [String] -> Word -> String -> String -> Parsed r
h [String]
ls Word
n String
i String
e
  {-# INLINE unexpected #-}
  eof :: Parser ()
eof = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> () -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser ()
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> () -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser ())
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> () -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser ()
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> () -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h  case String
i of
                   []  [String] -> Word -> String -> () -> Parsed r
c [String]
ls Word
n String
i ()
                   String
_   [String] -> Word -> String -> String -> Parsed r
h [String]
ls Word
n String
i String
"Parsing.eof"
  {-# INLINABLE eof #-}
  notFollowedBy :: forall a. Show a => Parser a -> Parser ()
notFollowedBy Parser a
p = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> () -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser ()
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> () -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser ())
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> () -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser ()
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> () -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
                      Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p [String]
ls Word
n String
i
                                (\[String]
_ Word
_ String
_ a
_  [String] -> Word -> String -> String -> Parsed r
h [String]
ls Word
n String
i String
"Parsing.notFollowedBy")
                                (\[String]
_ Word
_ String
_ String
_  [String] -> Word -> String -> () -> Parsed r
c [String]
ls Word
n String
i ())
  {-# INLINE notFollowedBy #-}

instance CharParsing Parser where
  satisfy :: (Char -> Bool) -> Parser Char
satisfy Char -> Bool
f = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> Char -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser Char
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> Char -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser Char)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> Char -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser Char
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> Char -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h  case String
i of
                         Char
x : String
xs | Char -> Bool
f Char
x  [String] -> Word -> String -> Char -> Parsed r
c [String]
ls Word
n' String
xs Char
x
                                          where !n' :: Word
n' = Word
n Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1
                         String
_  [String] -> Word -> String -> String -> Parsed r
h [String]
ls Word
n String
i String
"CharParsing.satisfy"
  {-# INLINABLE satisfy #-}
  string :: String -> Parser String
string String
s = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser String
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser String)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser String
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> String -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h  case String -> String -> Maybe String
forall a. Eq a => [a] -> [a] -> Maybe [a]
stripPrefix String
s String
i of
                        Just String
i'  [String] -> Word -> String -> String -> Parsed r
c [String]
ls Word
n' String
i' String
s
                                    where !n' :: Word
n' = Word
n Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s)
                        Maybe String
Nothing  [String] -> Word -> String -> String -> Parsed r
h [String]
ls Word
n String
i String
"CharParsing.string"
  {-# INLINABLE string #-}

instance Monad Parser where
  return :: forall a. a -> Parser a
return = a -> Parser a
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
  {-# INLINE return #-}
  Parser a
p >>= :: forall a b. Parser a -> (a -> Parser b) -> Parser b
>>= a -> Parser b
f = (forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> b -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser b
forall α.
(forall r.
 [String]
 -> Word
 -> String
 -> ([String] -> Word -> String -> α -> Parsed r)
 -> ([String] -> Word -> String -> String -> Parsed r)
 -> Parsed r)
-> Parser α
Parser ((forall r.
  [String]
  -> Word
  -> String
  -> ([String] -> Word -> String -> b -> Parsed r)
  -> ([String] -> Word -> String -> String -> Parsed r)
  -> Parsed r)
 -> Parser b)
-> (forall r.
    [String]
    -> Word
    -> String
    -> ([String] -> Word -> String -> b -> Parsed r)
    -> ([String] -> Word -> String -> String -> Parsed r)
    -> Parsed r)
-> Parser b
forall a b. (a -> b) -> a -> b
$ \[String]
ls Word
n String
i [String] -> Word -> String -> b -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h 
              Parser a
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> a -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser a
p [String]
ls Word
n String
i
                        (\[String]
ls' Word
n' String
i' a
a  Parser b
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> b -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser (a -> Parser b
f a
a) [String]
ls' Word
n' String
i' [String] -> Word -> String -> b -> Parsed r
c [String] -> Word -> String -> String -> Parsed r
h) [String] -> Word -> String -> String -> Parsed r
h
  {-# INLINE (>>=) #-}
  >> :: forall a b. Parser a -> Parser b -> Parser b
(>>) = Parser a -> Parser b -> Parser b
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
  {-# INLINE (>>) #-}
#if !MIN_VERSION_base(4,13,0)
  fail = PC.unexpected
  {-# INLINE fail #-}
#endif

parse  Parser α  String  Parsed α
parse :: forall α. Parser α -> String -> Parsed α
parse Parser α
p String
i = Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
forall α.
Parser α
-> forall r.
   [String]
   -> Word
   -> String
   -> ([String] -> Word -> String -> α -> Parsed r)
   -> ([String] -> Word -> String -> String -> Parsed r)
   -> Parsed r
runParser Parser α
p [] Word
0 String
i (\[String]
_  Word
_ String
_ α
a  α -> Parsed α
forall a. a -> Parsed a
Parsed α
a)
                               (\[String]
ls Word
_ String
_ String
e  [String] -> String -> Parsed α
forall α. [String] -> String -> Parsed α
Malformed ([String] -> [String]
forall a. [a] -> [a]
reverse [String]
ls) String
e)
{-# INLINE parse #-}

-- | Use the built-in parser to parse a string. Intended for testing only.
builtInParser  ( μ . (Monad μ, CharParsing μ)  μ α)  String  Parsed α
builtInParser :: forall α.
(forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ α)
-> String -> Parsed α
builtInParser forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ α
p = Parser α -> String -> Parsed α
forall α. Parser α -> String -> Parsed α
parse Parser α
forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ α
p
{-# INLINE builtInParser #-}

-- | Parse a 'String' to extract the 'Textual' value.
parseString  Textual α  String  Parsed α
parseString :: forall α. Textual α => String -> Parsed α
parseString = Parser α -> String -> Parsed α
forall α. Parser α -> String -> Parsed α
parse (Parser α -> String -> Parsed α) -> Parser α -> String -> Parsed α
forall a b. (a -> b) -> a -> b
$ Parser α
forall α (μ :: * -> *). (Textual α, Monad μ, CharParsing μ) => μ α
forall (μ :: * -> *). (Monad μ, CharParsing μ) => μ α
textual Parser α -> Parser () -> Parser α
forall a b. Parser a -> Parser b -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
forall (m :: * -> *). Parsing m => m ()
PC.eof
{-# INLINE parseString #-}

-- | Provide a hint for the type system when using 'parseString'.
parseStringAs  Textual α  p α  String  Parsed α
parseStringAs :: forall α (p :: * -> *). Textual α => p α -> String -> Parsed α
parseStringAs p α
_ = String -> Parsed α
forall α. Textual α => String -> Parsed α
parseString
{-# INLINE parseStringAs #-}

-- | Parse a 'TS.Text' to extract the 'Textual' value.
parseText  Textual α  TS.Text  Parsed α
parseText :: forall α. Textual α => Text -> Parsed α
parseText = String -> Parsed α
forall α. Textual α => String -> Parsed α
parseString (String -> Parsed α) -> (Text -> String) -> Text -> Parsed α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
TS.unpack
{-# INLINE parseText #-}

-- | Provide a hint for the type system when using 'parseText'.
parseTextAs  Textual α  p α  TS.Text  Parsed α
parseTextAs :: forall α (p :: * -> *). Textual α => p α -> Text -> Parsed α
parseTextAs p α
_ = Text -> Parsed α
forall α. Textual α => Text -> Parsed α
parseText
{-# INLINE parseTextAs #-}

-- | Parse a lazy 'TL.Text' to extract the 'Textual' value.
parseLazyText  Textual α  TL.Text  Parsed α
parseLazyText :: forall α. Textual α => Text -> Parsed α
parseLazyText = String -> Parsed α
forall α. Textual α => String -> Parsed α
parseString (String -> Parsed α) -> (Text -> String) -> Text -> Parsed α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
TL.unpack
{-# INLINE parseLazyText #-}

-- | Provide a hint for the type system when using 'parseLazyText'.
parseLazyTextAs  Textual α  p α  TL.Text  Parsed α
parseLazyTextAs :: forall α (p :: * -> *). Textual α => p α -> Text -> Parsed α
parseLazyTextAs p α
_ = Text -> Parsed α
forall α. Textual α => Text -> Parsed α
parseLazyText
{-# INLINE parseLazyTextAs #-}

-- | Decode and parse an ASCII 'BS.ByteString' to extract the 'Textual' value.
parseAscii  Textual α  BS.ByteString  Parsed α
parseAscii :: forall α. Textual α => ByteString -> Parsed α
parseAscii = String -> Parsed α
forall α. Textual α => String -> Parsed α
parseString (String -> Parsed α)
-> (ByteString -> String) -> ByteString -> Parsed α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BS8.unpack
{-# INLINE parseAscii #-}

-- | Provide a hint for the type system when using 'parseAscii'.
parseAsciiAs  Textual α  p α  BS.ByteString  Parsed α
parseAsciiAs :: forall α (p :: * -> *). Textual α => p α -> ByteString -> Parsed α
parseAsciiAs p α
_ = ByteString -> Parsed α
forall α. Textual α => ByteString -> Parsed α
parseAscii
{-# INLINE parseAsciiAs #-}

-- | Decode and parse a lazy ASCII 'BL.ByteString' to extract
--   the 'Textual' value.
parseLazyAscii  Textual α  BL.ByteString  Parsed α
parseLazyAscii :: forall α. Textual α => ByteString -> Parsed α
parseLazyAscii = String -> Parsed α
forall α. Textual α => String -> Parsed α
parseString (String -> Parsed α)
-> (ByteString -> String) -> ByteString -> Parsed α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BL8.unpack
{-# INLINE parseLazyAscii #-}

-- | Provide a hint for the type system when using 'parseLazyAscii'.
parseLazyAsciiAs  Textual α  BL.ByteString  Parsed α
parseLazyAsciiAs :: forall α. Textual α => ByteString -> Parsed α
parseLazyAsciiAs = String -> Parsed α
forall α. Textual α => String -> Parsed α
parseString (String -> Parsed α)
-> (ByteString -> String) -> ByteString -> Parsed α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BL8.unpack
{-# INLINE parseLazyAsciiAs #-}

-- | Decode and parse a UTF-8 'BS.ByteString' to extract the 'Textual' value.
parseUtf8  Textual α  BS.ByteString  Parsed α
parseUtf8 :: forall α. Textual α => ByteString -> Parsed α
parseUtf8 = Text -> Parsed α
forall α. Textual α => Text -> Parsed α
parseLazyText (Text -> Parsed α)
-> (ByteString -> Text) -> ByteString -> Parsed α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
decodeUtf8 (ByteString -> Text)
-> (ByteString -> ByteString) -> ByteString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BL.fromStrict
{-# INLINE parseUtf8 #-}

-- | Provide a hint for the type system when using 'parseUtf8'.
parseUtf8As  Textual α  p α  BS.ByteString  Parsed α
parseUtf8As :: forall α (p :: * -> *). Textual α => p α -> ByteString -> Parsed α
parseUtf8As p α
_ = ByteString -> Parsed α
forall α. Textual α => ByteString -> Parsed α
parseUtf8
{-# INLINE parseUtf8As #-}

-- | Decode and parse a lazy UTF-8 'BL.ByteString' to extract
--   the 'Textual' value.
parseLazyUtf8  Textual α  BL.ByteString  Parsed α
parseLazyUtf8 :: forall α. Textual α => ByteString -> Parsed α
parseLazyUtf8 = Text -> Parsed α
forall α. Textual α => Text -> Parsed α
parseLazyText (Text -> Parsed α)
-> (ByteString -> Text) -> ByteString -> Parsed α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
decodeUtf8
{-# INLINE parseLazyUtf8 #-}

-- | Provide a hint for the type system when using 'parseLazyUtf8'.
parseLazyUtf8As  Textual α  p α  BL.ByteString  Parsed α
parseLazyUtf8As :: forall α (p :: * -> *). Textual α => p α -> ByteString -> Parsed α
parseLazyUtf8As p α
_ = ByteString -> Parsed α
forall α. Textual α => ByteString -> Parsed α
parseLazyUtf8
{-# INLINE parseLazyUtf8As #-}

-- | A shorthand for @'maybeParsed' . 'parseString'@
fromString  Textual α  String  Maybe α
fromString :: forall α. Textual α => String -> Maybe α
fromString = Parsed α -> Maybe α
forall α. Parsed α -> Maybe α
maybeParsed (Parsed α -> Maybe α) -> (String -> Parsed α) -> String -> Maybe α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Parsed α
forall α. Textual α => String -> Parsed α
parseString
{-# INLINE fromString #-}

-- | Provide a hint for the type system when using 'fromString'.
fromStringAs  Textual α  p α  String  Maybe α
fromStringAs :: forall α (p :: * -> *). Textual α => p α -> String -> Maybe α
fromStringAs p α
_ = String -> Maybe α
forall α. Textual α => String -> Maybe α
fromString
{-# INLINE fromStringAs #-}

-- | A shorthand for @'maybeParsed' . 'parseText'@
fromText  Textual α  TS.Text  Maybe α
fromText :: forall α. Textual α => Text -> Maybe α
fromText = Parsed α -> Maybe α
forall α. Parsed α -> Maybe α
maybeParsed (Parsed α -> Maybe α) -> (Text -> Parsed α) -> Text -> Maybe α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Parsed α
forall α. Textual α => Text -> Parsed α
parseText
{-# INLINE fromText #-}

-- | Provide a hint for the type system when using 'fromText'.
fromTextAs  Textual α  p α  TS.Text  Maybe α
fromTextAs :: forall α (p :: * -> *). Textual α => p α -> Text -> Maybe α
fromTextAs p α
_ = Text -> Maybe α
forall α. Textual α => Text -> Maybe α
fromText
{-# INLINE fromTextAs #-}

-- | A shorthand for @'maybeParsed' . 'parseLazyText'@
fromLazyText  Textual α  TL.Text  Maybe α
fromLazyText :: forall α. Textual α => Text -> Maybe α
fromLazyText = Parsed α -> Maybe α
forall α. Parsed α -> Maybe α
maybeParsed (Parsed α -> Maybe α) -> (Text -> Parsed α) -> Text -> Maybe α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Parsed α
forall α. Textual α => Text -> Parsed α
parseLazyText
{-# INLINE fromLazyText #-}

-- | Provide a hint for the type system when using 'fromLazyText'.
fromLazyTextAs  Textual α  p α  TL.Text  Maybe α
fromLazyTextAs :: forall α (p :: * -> *). Textual α => p α -> Text -> Maybe α
fromLazyTextAs p α
_ = Text -> Maybe α
forall α. Textual α => Text -> Maybe α
fromLazyText
{-# INLINE fromLazyTextAs #-}

-- | A shorthand for @'maybeParsed' . 'parseAscii'@
fromAscii  Textual α  BS.ByteString  Maybe α
fromAscii :: forall α. Textual α => ByteString -> Maybe α
fromAscii = Parsed α -> Maybe α
forall α. Parsed α -> Maybe α
maybeParsed (Parsed α -> Maybe α)
-> (ByteString -> Parsed α) -> ByteString -> Maybe α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Parsed α
forall α. Textual α => ByteString -> Parsed α
parseAscii
{-# INLINE fromAscii #-}

-- | Provide a hint for the type system when using 'fromAscii'.
fromAsciiAs  Textual α  p α  BS.ByteString  Maybe α
fromAsciiAs :: forall α (p :: * -> *). Textual α => p α -> ByteString -> Maybe α
fromAsciiAs p α
_ = ByteString -> Maybe α
forall α. Textual α => ByteString -> Maybe α
fromAscii
{-# INLINE fromAsciiAs #-}

-- | A shorthand for @'maybeParsed' . 'parseLazyAscii'@
fromLazyAscii  Textual α  BL.ByteString  Maybe α
fromLazyAscii :: forall α. Textual α => ByteString -> Maybe α
fromLazyAscii = Parsed α -> Maybe α
forall α. Parsed α -> Maybe α
maybeParsed (Parsed α -> Maybe α)
-> (ByteString -> Parsed α) -> ByteString -> Maybe α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Parsed α
forall α. Textual α => ByteString -> Parsed α
parseLazyAscii
{-# INLINE fromLazyAscii #-}

-- | Provide a hint for the type system when using 'fromLazyAscii'.
fromLazyAsciiAs  Textual α  p α  BL.ByteString  Maybe α
fromLazyAsciiAs :: forall α (p :: * -> *). Textual α => p α -> ByteString -> Maybe α
fromLazyAsciiAs p α
_ = ByteString -> Maybe α
forall α. Textual α => ByteString -> Maybe α
fromLazyAscii
{-# INLINE fromLazyAsciiAs #-}

-- | A shorthand for @'maybeParsed' . 'parseUtf8'@
fromUtf8  Textual α  BS.ByteString  Maybe α
fromUtf8 :: forall α. Textual α => ByteString -> Maybe α
fromUtf8 = Parsed α -> Maybe α
forall α. Parsed α -> Maybe α
maybeParsed (Parsed α -> Maybe α)
-> (ByteString -> Parsed α) -> ByteString -> Maybe α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Parsed α
forall α. Textual α => ByteString -> Parsed α
parseUtf8
{-# INLINE fromUtf8 #-}

-- | Provide a hint for the type system when using 'fromUtf8'.
fromUtf8As  Textual α  p α  BS.ByteString  Maybe α
fromUtf8As :: forall α (p :: * -> *). Textual α => p α -> ByteString -> Maybe α
fromUtf8As p α
_ = ByteString -> Maybe α
forall α. Textual α => ByteString -> Maybe α
fromUtf8
{-# INLINE fromUtf8As #-}

-- | A shorthand for @'maybeParsed' . 'parseLazyUtf8'@
fromLazyUtf8  Textual α  BL.ByteString  Maybe α
fromLazyUtf8 :: forall α. Textual α => ByteString -> Maybe α
fromLazyUtf8 = Parsed α -> Maybe α
forall α. Parsed α -> Maybe α
maybeParsed (Parsed α -> Maybe α)
-> (ByteString -> Parsed α) -> ByteString -> Maybe α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Parsed α
forall α. Textual α => ByteString -> Parsed α
parseLazyUtf8
{-# INLINE fromLazyUtf8 #-}

-- | Provide a hint for the type system when using 'fromLazyUtf8'.
fromLazyUtf8As  Textual α  p α  BL.ByteString  Maybe α
fromLazyUtf8As :: forall α (p :: * -> *). Textual α => p α -> ByteString -> Maybe α
fromLazyUtf8As p α
_ = ByteString -> Maybe α
forall α. Textual α => ByteString -> Maybe α
fromLazyUtf8
{-# INLINE fromLazyUtf8As #-}