{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
#if __GLASGOW_HASKELL__ >= 900
{-# LANGUAGE ExplicitForAll #-}
#endif
module Data.TTC
(
Textual
, convert
, toS
, toT
, toTL
, toTLB
, toST
, toBS
, toBSL
, toBSB
, toSBS
, fromS
, fromT
, fromTL
, fromTLB
, fromST
, fromBS
, fromBSL
, fromBSB
, fromSBS
, asS
, asT
, asTL
, asTLB
, asST
, asBS
, asBSL
, asBSB
, asSBS
, Render(..)
, RenderDefault(..)
, renderS
, renderT
, renderTL
, renderTLB
, renderST
, renderBS
, renderBSL
, renderBSB
, renderSBS
, renderWithShow
, Parse(..)
, ParseDefault(..)
, parseS
, parseT
, parseTL
, parseTLB
, parseST
, parseBS
, parseBSL
, parseBSB
, parseSBS
, parseMaybe
, parseMaybeS
, parseMaybeT
, parseMaybeTL
, parseMaybeTLB
, parseMaybeST
, parseMaybeBS
, parseMaybeBSL
, parseMaybeBSB
, parseMaybeSBS
, parseOrFail
, parseOrFailS
, parseOrFailT
, parseOrFailTL
, parseOrFailTLB
, parseOrFailST
, parseOrFailBS
, parseOrFailBSL
, parseOrFailBSB
, parseOrFailSBS
, parseUnsafe
, parseUnsafeS
, parseUnsafeT
, parseUnsafeTL
, parseUnsafeTLB
, parseUnsafeST
, parseUnsafeBS
, parseUnsafeBSL
, parseUnsafeBSB
, parseUnsafeSBS
, withError
, withErrorS
, withErrorT
, withErrorTL
, withErrorTLB
, withErrorST
, withErrorBS
, withErrorBSL
, withErrorBSB
, withErrorSBS
, prefixError
, prefixErrorS
, prefixErrorT
, prefixErrorTL
, prefixErrorTLB
, prefixErrorST
, prefixErrorBS
, prefixErrorBSL
, prefixErrorBSB
, prefixErrorSBS
, parseEnum
, parseEnum'
, parseWithRead
, parseWithRead'
, maybeParseWithRead
, readsEnum
, readsWithParse
, valid
, validOf
, mkValid
, untypedValidOf
, mkUntypedValid
, mkUntypedValidQQ
) where
#if __GLASGOW_HASKELL__ <= 806
import Control.Monad.Fail (MonadFail)
#endif
import Data.Int (Int16, Int32, Int64, Int8)
import Data.Proxy (Proxy(Proxy), asProxyTypeOf)
import Data.String (IsString(fromString))
import Data.Word (Word16, Word32, Word64, Word8)
import GHC.Stack (HasCallStack)
import Text.Read (readMaybe)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Builder as BSB
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Short as SBS
import qualified Language.Haskell.TH as TH
import qualified Language.Haskell.TH.Quote as Q
import qualified Language.Haskell.TH.Syntax as THS
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Text.Encoding.Error as TEE
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TLB
import qualified Data.Text.Lazy.Encoding as TLE
import qualified Data.Text.Short as ST
class Textual t where
toS :: t -> String
toT :: t -> T.Text
toTL :: t -> TL.Text
toTLB :: t -> TLB.Builder
toST :: t -> ST.ShortText
toBS :: t -> BS.ByteString
toBSL :: t -> BSL.ByteString
toBSB :: t -> BSB.Builder
toSBS :: t -> SBS.ShortByteString
convert :: Textual t' => t' -> t
instance Textual String where
toS :: String -> String
toS = forall a. a -> a
id
toT :: String -> Text
toT = String -> Text
T.pack
toTL :: String -> Text
toTL = String -> Text
TL.pack
toTLB :: String -> Builder
toTLB = String -> Builder
TLB.fromString
toST :: String -> ShortText
toST = String -> ShortText
ST.fromString
toBS :: String -> ByteString
toBS = Text -> ByteString
TE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
toBSL :: String -> ByteString
toBSL = Text -> ByteString
TLE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
TL.pack
toBSB :: String -> Builder
toBSB = ByteString -> Builder
BSB.byteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
toSBS :: String -> ShortByteString
toSBS = ByteString -> ShortByteString
SBS.toShort forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
convert :: forall t'. Textual t' => t' -> String
convert = forall t'. Textual t' => t' -> String
toS
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
instance Textual T.Text where
toS :: Text -> String
toS = Text -> String
T.unpack
toT :: Text -> Text
toT = forall a. a -> a
id
toTL :: Text -> Text
toTL = Text -> Text
TL.fromStrict
toTLB :: Text -> Builder
toTLB = Text -> Builder
TLB.fromText
toST :: Text -> ShortText
toST = Text -> ShortText
ST.fromText
toBS :: Text -> ByteString
toBS = Text -> ByteString
TE.encodeUtf8
toBSL :: Text -> ByteString
toBSL = Text -> ByteString
TLE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.fromStrict
toBSB :: Text -> Builder
toBSB = ByteString -> Builder
BSB.byteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TE.encodeUtf8
toSBS :: Text -> ShortByteString
toSBS = ByteString -> ShortByteString
SBS.toShort forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TE.encodeUtf8
convert :: forall t'. Textual t' => t' -> Text
convert = forall t'. Textual t' => t' -> Text
toT
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
instance Textual TL.Text where
toS :: Text -> String
toS = Text -> String
TL.unpack
toT :: Text -> Text
toT = Text -> Text
TL.toStrict
toTL :: Text -> Text
toTL = forall a. a -> a
id
toTLB :: Text -> Builder
toTLB = Text -> Builder
TLB.fromLazyText
toST :: Text -> ShortText
toST = Text -> ShortText
ST.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.toStrict
toBS :: Text -> ByteString
toBS = ByteString -> ByteString
BSL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TLE.encodeUtf8
toBSL :: Text -> ByteString
toBSL = Text -> ByteString
TLE.encodeUtf8
toBSB :: Text -> Builder
toBSB = ByteString -> Builder
BSB.lazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TLE.encodeUtf8
toSBS :: Text -> ShortByteString
toSBS = ByteString -> ShortByteString
SBS.toShort forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BSL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TLE.encodeUtf8
convert :: forall t'. Textual t' => t' -> Text
convert = forall t'. Textual t' => t' -> Text
toTL
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
instance Textual TLB.Builder where
toS :: Builder -> String
toS = Text -> String
TL.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
TLB.toLazyText
toT :: Builder -> Text
toT = Text -> Text
TL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
TLB.toLazyText
toTL :: Builder -> Text
toTL = Builder -> Text
TLB.toLazyText
toTLB :: Builder -> Builder
toTLB = forall a. a -> a
id
toST :: Builder -> ShortText
toST = Text -> ShortText
ST.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
TLB.toLazyText
toBS :: Builder -> ByteString
toBS = ByteString -> ByteString
BSL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TLE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
TLB.toLazyText
toBSL :: Builder -> ByteString
toBSL = Text -> ByteString
TLE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
TLB.toLazyText
toBSB :: Builder -> Builder
toBSB = ByteString -> Builder
BSB.lazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TLE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
TLB.toLazyText
toSBS :: Builder -> ShortByteString
toSBS = ByteString -> ShortByteString
SBS.toShort forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BSL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TLE.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
TLB.toLazyText
convert :: forall t'. Textual t' => t' -> Builder
convert = forall t'. Textual t' => t' -> Builder
toTLB
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
instance Textual ST.ShortText where
toS :: ShortText -> String
toS = ShortText -> String
ST.toString
toT :: ShortText -> Text
toT = ShortText -> Text
ST.toText
toTL :: ShortText -> Text
toTL = Text -> Text
TL.fromStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> Text
ST.toText
toTLB :: ShortText -> Builder
toTLB = Text -> Builder
TLB.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> Text
ST.toText
toST :: ShortText -> ShortText
toST = forall a. a -> a
id
toBS :: ShortText -> ByteString
toBS = ShortText -> ByteString
ST.toByteString
toBSL :: ShortText -> ByteString
toBSL = ByteString -> ByteString
BSL.fromStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> ByteString
ST.toByteString
toBSB :: ShortText -> Builder
toBSB = ByteString -> Builder
BSB.byteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> ByteString
ST.toByteString
toSBS :: ShortText -> ShortByteString
toSBS = ShortText -> ShortByteString
ST.toShortByteString
convert :: forall t'. Textual t' => t' -> ShortText
convert = forall t'. Textual t' => t' -> ShortText
toST
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
instance Textual BS.ByteString where
toS :: ByteString -> String
toS = Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toT :: ByteString -> Text
toT = OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toTL :: ByteString -> Text
toTL = OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BSL.fromStrict
toTLB :: ByteString -> Builder
toTLB = Text -> Builder
TLB.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toST :: ByteString -> ShortText
toST = Text -> ShortText
ST.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toBS :: ByteString -> ByteString
toBS = forall a. a -> a
id
toBSL :: ByteString -> ByteString
toBSL = ByteString -> ByteString
BSL.fromStrict
toBSB :: ByteString -> Builder
toBSB = ByteString -> Builder
BSB.byteString
toSBS :: ByteString -> ShortByteString
toSBS = ByteString -> ShortByteString
SBS.toShort
convert :: forall t'. Textual t' => t' -> ByteString
convert = forall t'. Textual t' => t' -> ByteString
toBS
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
instance Textual BSL.ByteString where
toS :: ByteString -> String
toS = Text -> String
TL.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toT :: ByteString -> Text
toT = Text -> Text
TL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toTL :: ByteString -> Text
toTL = OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toTLB :: ByteString -> Builder
toTLB = Text -> Builder
TLB.fromLazyText forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toST :: ByteString -> ShortText
toST = Text -> ShortText
ST.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode
toBS :: ByteString -> ByteString
toBS = ByteString -> ByteString
BSL.toStrict
toBSL :: ByteString -> ByteString
toBSL = forall a. a -> a
id
toBSB :: ByteString -> Builder
toBSB = ByteString -> Builder
BSB.lazyByteString
toSBS :: ByteString -> ShortByteString
toSBS = ByteString -> ShortByteString
SBS.toShort forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BSL.toStrict
convert :: forall t'. Textual t' => t' -> ByteString
convert = forall t'. Textual t' => t' -> ByteString
toBSL
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
instance Textual BSB.Builder where
toS :: Builder -> String
toS =
Text -> String
TL.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BSB.toLazyByteString
toT :: Builder -> Text
toT =
Text -> Text
TL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BSB.toLazyByteString
toTL :: Builder -> Text
toTL = OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BSB.toLazyByteString
toTLB :: Builder -> Builder
toTLB
= Text -> Builder
TLB.fromLazyText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BSB.toLazyByteString
toST :: Builder -> ShortText
toST
= Text -> ShortText
ST.fromText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.toStrict
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BSB.toLazyByteString
toBS :: Builder -> ByteString
toBS = ByteString -> ByteString
BSL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BSB.toLazyByteString
toBSL :: Builder -> ByteString
toBSL = Builder -> ByteString
BSB.toLazyByteString
toBSB :: Builder -> Builder
toBSB = forall a. a -> a
id
toSBS :: Builder -> ShortByteString
toSBS = ByteString -> ShortByteString
SBS.toShort forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BSL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BSB.toLazyByteString
convert :: forall t'. Textual t' => t' -> Builder
convert = forall t'. Textual t' => t' -> Builder
toBSB
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
instance Textual SBS.ShortByteString where
toS :: ShortByteString -> String
toS = Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
SBS.fromShort
toT :: ShortByteString -> Text
toT = OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
SBS.fromShort
toTL :: ShortByteString -> Text
toTL = OnDecodeError -> ByteString -> Text
TLE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BSL.fromStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
SBS.fromShort
toTLB :: ShortByteString -> Builder
toTLB = Text -> Builder
TLB.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
SBS.fromShort
toST :: ShortByteString -> ShortText
toST = Text -> ShortText
ST.fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
TEE.lenientDecode forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
SBS.fromShort
toBS :: ShortByteString -> ByteString
toBS = ShortByteString -> ByteString
SBS.fromShort
toBSL :: ShortByteString -> ByteString
toBSL = ByteString -> ByteString
BSL.fromStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
SBS.fromShort
toBSB :: ShortByteString -> Builder
toBSB = ByteString -> Builder
BSB.byteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
SBS.fromShort
toSBS :: ShortByteString -> ShortByteString
toSBS = forall a. a -> a
id
convert :: forall t'. Textual t' => t' -> ShortByteString
convert = forall t'. Textual t' => t' -> ShortByteString
toSBS
{-# INLINE toS #-}
{-# INLINE toT #-}
{-# INLINE toTL #-}
{-# INLINE toTLB #-}
{-# INLINE toST #-}
{-# INLINE toBS #-}
{-# INLINE toBSL #-}
{-# INLINE toBSB #-}
{-# INLINE toSBS #-}
{-# INLINE convert #-}
fromS :: Textual t => String -> t
fromS :: forall t. Textual t => String -> t
fromS = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromS #-}
fromT :: Textual t => T.Text -> t
fromT :: forall t. Textual t => Text -> t
fromT = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromT #-}
fromTL :: Textual t => TL.Text -> t
fromTL :: forall t. Textual t => Text -> t
fromTL = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromTL #-}
fromTLB :: Textual t => TLB.Builder -> t
fromTLB :: forall t. Textual t => Builder -> t
fromTLB = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromTLB #-}
fromST :: Textual t => ST.ShortText -> t
fromST :: forall t. Textual t => ShortText -> t
fromST = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromST #-}
fromBS :: Textual t => BS.ByteString -> t
fromBS :: forall t. Textual t => ByteString -> t
fromBS = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromBS #-}
fromBSL :: Textual t => BSL.ByteString -> t
fromBSL :: forall t. Textual t => ByteString -> t
fromBSL = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromBSL #-}
fromBSB :: Textual t => BSB.Builder -> t
fromBSB :: forall t. Textual t => Builder -> t
fromBSB = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromBSB #-}
fromSBS :: Textual t => SBS.ShortByteString -> t
fromSBS :: forall t. Textual t => ShortByteString -> t
fromSBS = forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE fromSBS #-}
asS :: Textual t => (String -> a) -> t -> a
asS :: forall t a. Textual t => (String -> a) -> t -> a
asS String -> a
f = String -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asS #-}
asT :: Textual t => (T.Text -> a) -> t -> a
asT :: forall t a. Textual t => (Text -> a) -> t -> a
asT Text -> a
f = Text -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asT #-}
asTL :: Textual t => (TL.Text -> a) -> t -> a
asTL :: forall t a. Textual t => (Text -> a) -> t -> a
asTL Text -> a
f = Text -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asTL #-}
asTLB :: Textual t => (TLB.Builder -> a) -> t -> a
asTLB :: forall t a. Textual t => (Builder -> a) -> t -> a
asTLB Builder -> a
f = Builder -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asTLB #-}
asST :: Textual t => (ST.ShortText -> a) -> t -> a
asST :: forall t a. Textual t => (ShortText -> a) -> t -> a
asST ShortText -> a
f = ShortText -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asST #-}
asBS :: Textual t => (BS.ByteString -> a) -> t -> a
asBS :: forall t a. Textual t => (ByteString -> a) -> t -> a
asBS ByteString -> a
f = ByteString -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asBS #-}
asBSL :: Textual t => (BSL.ByteString -> a) -> t -> a
asBSL :: forall t a. Textual t => (ByteString -> a) -> t -> a
asBSL ByteString -> a
f = ByteString -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asBSL #-}
asBSB :: Textual t => (BSB.Builder -> a ) -> t -> a
asBSB :: forall t a. Textual t => (Builder -> a) -> t -> a
asBSB Builder -> a
f = Builder -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asBSB #-}
asSBS :: Textual t => (SBS.ShortByteString -> a) -> t -> a
asSBS :: forall t a. Textual t => (ShortByteString -> a) -> t -> a
asSBS ShortByteString -> a
f = ShortByteString -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert
{-# INLINE asSBS #-}
class Render a where
render :: Textual t => a -> t
default render :: (RenderDefault a, Textual t) => a -> t
render = forall a t. (RenderDefault a, Textual t) => a -> t
renderDefault
class RenderDefault a where
renderDefault :: Textual t => a -> t
instance RenderDefault Char where
renderDefault :: forall t. Textual t => Char -> t
renderDefault Char
c = forall t. Textual t => String -> t
fromS [Char
c]
instance RenderDefault Double where
renderDefault :: forall t. Textual t => Double -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Float where
renderDefault :: forall t. Textual t => Float -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Int where
renderDefault :: forall t. Textual t => Int -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Int8 where
renderDefault :: forall t. Textual t => Int8 -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Int16 where
renderDefault :: forall t. Textual t => Int16 -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Int32 where
renderDefault :: forall t. Textual t => Int32 -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Int64 where
renderDefault :: forall t. Textual t => Int64 -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Integer where
renderDefault :: forall t. Textual t => Integer -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Word where
renderDefault :: forall t. Textual t => Word -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Word8 where
renderDefault :: forall t. Textual t => Word8 -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Word16 where
renderDefault :: forall t. Textual t => Word16 -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Word32 where
renderDefault :: forall t. Textual t => Word32 -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault Word64 where
renderDefault :: forall t. Textual t => Word64 -> t
renderDefault = forall a t. (Show a, Textual t) => a -> t
renderWithShow
instance RenderDefault String where
renderDefault :: forall t. Textual t => String -> t
renderDefault = forall t. Textual t => String -> t
fromS
instance RenderDefault BSL.ByteString where
renderDefault :: forall t. Textual t => ByteString -> t
renderDefault = forall t. Textual t => ByteString -> t
fromBSL
instance RenderDefault BS.ByteString where
renderDefault :: forall t. Textual t => ByteString -> t
renderDefault = forall t. Textual t => ByteString -> t
fromBS
instance RenderDefault TL.Text where
renderDefault :: forall t. Textual t => Text -> t
renderDefault = forall t. Textual t => Text -> t
fromTL
instance RenderDefault T.Text where
renderDefault :: forall t. Textual t => Text -> t
renderDefault = forall t. Textual t => Text -> t
fromT
renderS :: Render a => a -> String
renderS :: forall a. Render a => a -> String
renderS = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderS #-}
renderT :: Render a => a -> T.Text
renderT :: forall a. Render a => a -> Text
renderT = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderT #-}
renderTL :: Render a => a -> TL.Text
renderTL :: forall a. Render a => a -> Text
renderTL = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderTL #-}
renderTLB :: Render a => a -> TLB.Builder
renderTLB :: forall a. Render a => a -> Builder
renderTLB = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderTLB #-}
renderST :: Render a => a -> ST.ShortText
renderST :: forall a. Render a => a -> ShortText
renderST = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderST #-}
renderBS :: Render a => a -> BS.ByteString
renderBS :: forall a. Render a => a -> ByteString
renderBS = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderBS #-}
renderBSL :: Render a => a -> BSL.ByteString
renderBSL :: forall a. Render a => a -> ByteString
renderBSL = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderBSL #-}
renderBSB :: Render a => a -> BSB.Builder
renderBSB :: forall a. Render a => a -> Builder
renderBSB = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderBSB #-}
renderSBS :: Render a => a -> SBS.ShortByteString
renderSBS :: forall a. Render a => a -> ShortByteString
renderSBS = forall a t. (Render a, Textual t) => a -> t
render
{-# INLINE renderSBS #-}
renderWithShow :: (Show a, Textual t) => a -> t
renderWithShow :: forall a t. (Show a, Textual t) => a -> t
renderWithShow = forall t t'. (Textual t, Textual t') => t' -> t
convert forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
{-# INLINE renderWithShow #-}
class Parse a where
parse :: (Textual t, Textual e) => t -> Either e a
default parse :: (Textual t, Textual e, ParseDefault a) => t -> Either e a
parse = forall a t e.
(ParseDefault a, Textual t, Textual e) =>
t -> Either e a
parseDefault
parse' :: (Parse a, Textual t) => t -> Either String a
parse' :: forall a t. (Parse a, Textual t) => t -> Either String a
parse' = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parse' #-}
class ParseDefault a where
parseDefault :: (Textual t, Textual e) => t -> Either e a
instance ParseDefault Char where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Char
parseDefault = forall t a. Textual t => (String -> a) -> t -> a
asS forall a b. (a -> b) -> a -> b
$ \case
[Char
c] -> forall a b. b -> Either a b
Right Char
c
String
_cs -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall t. Textual t => String -> t
fromS String
"invalid Char"
instance ParseDefault Double where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Double
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Double"
instance ParseDefault Float where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Float
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Float"
instance ParseDefault Int where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Int
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Int"
instance ParseDefault Int8 where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Int8
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Int8"
instance ParseDefault Int16 where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Int16
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Int16"
instance ParseDefault Int32 where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Int32
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Int32"
instance ParseDefault Int64 where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Int64
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Int64"
instance ParseDefault Integer where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Integer
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Integer"
instance ParseDefault Word where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Word
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Word"
instance ParseDefault Word8 where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Word8
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Word8"
instance ParseDefault Word16 where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Word16
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Word16"
instance ParseDefault Word32 where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Word32
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Word32"
instance ParseDefault Word64 where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Word64
parseDefault = forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
"Word64"
instance ParseDefault String where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e String
parseDefault = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t'. Textual t' => t' -> String
toS
instance ParseDefault BSL.ByteString where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e ByteString
parseDefault = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t'. Textual t' => t' -> ByteString
toBSL
instance ParseDefault BS.ByteString where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e ByteString
parseDefault = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t'. Textual t' => t' -> ByteString
toBS
instance ParseDefault TL.Text where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Text
parseDefault = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t'. Textual t' => t' -> Text
toTL
instance ParseDefault T.Text where
parseDefault :: forall t e. (Textual t, Textual e) => t -> Either e Text
parseDefault = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t'. Textual t' => t' -> Text
toT
parseS :: (Parse a, Textual e) => String -> Either e a
parseS :: forall a e. (Parse a, Textual e) => String -> Either e a
parseS = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseS #-}
parseT :: (Parse a, Textual e) => T.Text -> Either e a
parseT :: forall a e. (Parse a, Textual e) => Text -> Either e a
parseT = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseT #-}
parseTL :: (Parse a, Textual e) => TL.Text -> Either e a
parseTL :: forall a e. (Parse a, Textual e) => Text -> Either e a
parseTL = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseTL #-}
parseTLB :: (Parse a, Textual e) => TLB.Builder -> Either e a
parseTLB :: forall a e. (Parse a, Textual e) => Builder -> Either e a
parseTLB = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseTLB #-}
parseST :: (Parse a, Textual e) => ST.ShortText -> Either e a
parseST :: forall a e. (Parse a, Textual e) => ShortText -> Either e a
parseST = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseST #-}
parseBS :: (Parse a, Textual e) => BS.ByteString -> Either e a
parseBS :: forall a e. (Parse a, Textual e) => ByteString -> Either e a
parseBS = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseBS #-}
parseBSL :: (Parse a, Textual e) => BSL.ByteString -> Either e a
parseBSL :: forall a e. (Parse a, Textual e) => ByteString -> Either e a
parseBSL = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseBSL #-}
parseBSB :: (Parse a, Textual e) => BSB.Builder -> Either e a
parseBSB :: forall a e. (Parse a, Textual e) => Builder -> Either e a
parseBSB = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseBSB #-}
parseSBS :: (Parse a, Textual e) => SBS.ShortByteString -> Either e a
parseSBS :: forall a e. (Parse a, Textual e) => ShortByteString -> Either e a
parseSBS = forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseSBS #-}
parseMaybe :: (Parse a, Textual t) => t -> Maybe a
parseMaybe :: forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const forall a. Maybe a
Nothing) forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a t. (Parse a, Textual t) => t -> Either String a
parse'
{-# INLINE parseMaybe #-}
parseMaybeS :: Parse a => String -> Maybe a
parseMaybeS :: forall a. Parse a => String -> Maybe a
parseMaybeS = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeS #-}
parseMaybeT :: Parse a => T.Text -> Maybe a
parseMaybeT :: forall a. Parse a => Text -> Maybe a
parseMaybeT = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeT #-}
parseMaybeTL :: Parse a => TL.Text -> Maybe a
parseMaybeTL :: forall a. Parse a => Text -> Maybe a
parseMaybeTL = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeTL #-}
parseMaybeTLB :: Parse a => TLB.Builder -> Maybe a
parseMaybeTLB :: forall a. Parse a => Builder -> Maybe a
parseMaybeTLB = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeTLB #-}
parseMaybeST :: Parse a => ST.ShortText -> Maybe a
parseMaybeST :: forall a. Parse a => ShortText -> Maybe a
parseMaybeST = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeST #-}
parseMaybeBS :: Parse a => BS.ByteString -> Maybe a
parseMaybeBS :: forall a. Parse a => ByteString -> Maybe a
parseMaybeBS = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeBS #-}
parseMaybeBSL :: Parse a => BSL.ByteString -> Maybe a
parseMaybeBSL :: forall a. Parse a => ByteString -> Maybe a
parseMaybeBSL = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeBSL #-}
parseMaybeBSB :: Parse a => BSB.Builder -> Maybe a
parseMaybeBSB :: forall a. Parse a => Builder -> Maybe a
parseMaybeBSB = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeBSB #-}
parseMaybeSBS :: Parse a => SBS.ShortByteString -> Maybe a
parseMaybeSBS :: forall a. Parse a => ShortByteString -> Maybe a
parseMaybeSBS = forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe
{-# INLINE parseMaybeSBS #-}
parseOrFail :: (MonadFail m, Parse a, Textual t) => t -> m a
parseOrFail :: forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseOrFail #-}
parseOrFailS :: (MonadFail m, Parse a) => String -> m a
parseOrFailS :: forall (m :: * -> *) a. (MonadFail m, Parse a) => String -> m a
parseOrFailS = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailS #-}
parseOrFailT :: (MonadFail m, Parse a) => T.Text -> m a
parseOrFailT :: forall (m :: * -> *) a. (MonadFail m, Parse a) => Text -> m a
parseOrFailT = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailT #-}
parseOrFailTL :: (MonadFail m, Parse a) => TL.Text -> m a
parseOrFailTL :: forall (m :: * -> *) a. (MonadFail m, Parse a) => Text -> m a
parseOrFailTL = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailTL #-}
parseOrFailTLB :: (MonadFail m, Parse a) => TLB.Builder -> m a
parseOrFailTLB :: forall (m :: * -> *) a. (MonadFail m, Parse a) => Builder -> m a
parseOrFailTLB = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailTLB #-}
parseOrFailST :: (MonadFail m, Parse a) => ST.ShortText -> m a
parseOrFailST :: forall (m :: * -> *) a. (MonadFail m, Parse a) => ShortText -> m a
parseOrFailST = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailST #-}
parseOrFailBS :: (MonadFail m, Parse a) => BS.ByteString -> m a
parseOrFailBS :: forall (m :: * -> *) a. (MonadFail m, Parse a) => ByteString -> m a
parseOrFailBS = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailBS #-}
parseOrFailBSL :: (MonadFail m, Parse a) => BSL.ByteString -> m a
parseOrFailBSL :: forall (m :: * -> *) a. (MonadFail m, Parse a) => ByteString -> m a
parseOrFailBSL = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailBSL #-}
parseOrFailBSB :: (MonadFail m, Parse a) => BSB.Builder -> m a
parseOrFailBSB :: forall (m :: * -> *) a. (MonadFail m, Parse a) => Builder -> m a
parseOrFailBSB = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailBSB #-}
parseOrFailSBS :: (MonadFail m, Parse a) => SBS.ShortByteString -> m a
parseOrFailSBS :: forall (m :: * -> *) a.
(MonadFail m, Parse a) =>
ShortByteString -> m a
parseOrFailSBS = forall (m :: * -> *) a t.
(MonadFail m, Parse a, Textual t) =>
t -> m a
parseOrFail
{-# INLINE parseOrFailSBS #-}
parseUnsafe :: (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe :: forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => String -> a
error forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
"parseUnsafe: " forall a. [a] -> [a] -> [a]
++)) forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse
{-# INLINE parseUnsafe #-}
parseUnsafeS :: (HasCallStack, Parse a) => String -> a
parseUnsafeS :: forall a. (HasCallStack, Parse a) => String -> a
parseUnsafeS = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeS #-}
parseUnsafeT :: (HasCallStack, Parse a) => T.Text -> a
parseUnsafeT :: forall a. (HasCallStack, Parse a) => Text -> a
parseUnsafeT = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeT #-}
parseUnsafeTL :: (HasCallStack, Parse a) => TL.Text -> a
parseUnsafeTL :: forall a. (HasCallStack, Parse a) => Text -> a
parseUnsafeTL = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeTL #-}
parseUnsafeTLB :: (HasCallStack, Parse a) => TLB.Builder -> a
parseUnsafeTLB :: forall a. (HasCallStack, Parse a) => Builder -> a
parseUnsafeTLB = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeTLB #-}
parseUnsafeST :: (HasCallStack, Parse a) => ST.ShortText -> a
parseUnsafeST :: forall a. (HasCallStack, Parse a) => ShortText -> a
parseUnsafeST = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeST #-}
parseUnsafeBS :: (HasCallStack, Parse a) => BS.ByteString -> a
parseUnsafeBS :: forall a. (HasCallStack, Parse a) => ByteString -> a
parseUnsafeBS = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeBS #-}
parseUnsafeBSL :: (HasCallStack, Parse a) => BSL.ByteString -> a
parseUnsafeBSL :: forall a. (HasCallStack, Parse a) => ByteString -> a
parseUnsafeBSL = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeBSL #-}
parseUnsafeBSB :: (HasCallStack, Parse a) => BSB.Builder -> a
parseUnsafeBSB :: forall a. (HasCallStack, Parse a) => Builder -> a
parseUnsafeBSB = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeBSB #-}
parseUnsafeSBS :: (HasCallStack, Parse a) => SBS.ShortByteString -> a
parseUnsafeSBS :: forall a. (HasCallStack, Parse a) => ShortByteString -> a
parseUnsafeSBS = forall a t. (HasCallStack, Parse a, Textual t) => t -> a
parseUnsafe
{-# INLINE parseUnsafeSBS #-}
withError
:: (Textual e', Textual e)
=> e'
-> Maybe a
-> Either e a
withError :: forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError e'
err = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall t t'. (Textual t, Textual t') => t' -> t
convert e'
err) forall a b. b -> Either a b
Right
{-# INLINE withError #-}
withErrorS
:: Textual e
=> String
-> Maybe a
-> Either e a
withErrorS :: forall e a. Textual e => String -> Maybe a -> Either e a
withErrorS = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorS #-}
withErrorT
:: Textual e
=> T.Text
-> Maybe a
-> Either e a
withErrorT :: forall e a. Textual e => Text -> Maybe a -> Either e a
withErrorT = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorT #-}
withErrorTL
:: Textual e
=> TL.Text
-> Maybe a
-> Either e a
withErrorTL :: forall e a. Textual e => Text -> Maybe a -> Either e a
withErrorTL = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorTL #-}
withErrorTLB
:: Textual e
=> TLB.Builder
-> Maybe a
-> Either e a
withErrorTLB :: forall e a. Textual e => Builder -> Maybe a -> Either e a
withErrorTLB = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorTLB #-}
withErrorST
:: Textual e
=> ST.ShortText
-> Maybe a
-> Either e a
withErrorST :: forall e a. Textual e => ShortText -> Maybe a -> Either e a
withErrorST = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorST #-}
withErrorBS
:: Textual e
=> BS.ByteString
-> Maybe a
-> Either e a
withErrorBS :: forall e a. Textual e => ByteString -> Maybe a -> Either e a
withErrorBS = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorBS #-}
withErrorBSL
:: Textual e
=> BSL.ByteString
-> Maybe a
-> Either e a
withErrorBSL :: forall e a. Textual e => ByteString -> Maybe a -> Either e a
withErrorBSL = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorBSL #-}
withErrorBSB
:: Textual e
=> BSB.Builder
-> Maybe a
-> Either e a
withErrorBSB :: forall e a. Textual e => Builder -> Maybe a -> Either e a
withErrorBSB = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorBSB #-}
withErrorSBS
:: Textual e
=> SBS.ShortByteString
-> Maybe a
-> Either e a
withErrorSBS :: forall e a. Textual e => ShortByteString -> Maybe a -> Either e a
withErrorSBS = forall e' e a.
(Textual e', Textual e) =>
e' -> Maybe a -> Either e a
withError
{-# INLINE withErrorSBS #-}
prefixError
:: (Monoid e', Textual e', Textual e)
=> e'
-> Either e' a
-> Either e a
prefixError :: forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError e'
prefix = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> Either a b
Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t t'. (Textual t, Textual t') => t' -> t
convert forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => a -> a -> a
mappend e'
prefix) forall a b. b -> Either a b
Right
{-# INLINE prefixError #-}
prefixErrorS
:: Textual e
=> String
-> Either String a
-> Either e a
prefixErrorS :: forall e a. Textual e => String -> Either String a -> Either e a
prefixErrorS = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorS #-}
prefixErrorT
:: Textual e
=> T.Text
-> Either T.Text a
-> Either e a
prefixErrorT :: forall e a. Textual e => Text -> Either Text a -> Either e a
prefixErrorT = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorT #-}
prefixErrorTL
:: Textual e
=> TL.Text
-> Either TL.Text a
-> Either e a
prefixErrorTL :: forall e a. Textual e => Text -> Either Text a -> Either e a
prefixErrorTL = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorTL #-}
prefixErrorTLB
:: Textual e
=> TLB.Builder
-> Either TLB.Builder a
-> Either e a
prefixErrorTLB :: forall e a. Textual e => Builder -> Either Builder a -> Either e a
prefixErrorTLB = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorTLB #-}
prefixErrorST
:: Textual e
=> ST.ShortText
-> Either ST.ShortText a
-> Either e a
prefixErrorST :: forall e a.
Textual e =>
ShortText -> Either ShortText a -> Either e a
prefixErrorST = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorST #-}
prefixErrorBS
:: Textual e
=> BS.ByteString
-> Either BS.ByteString a
-> Either e a
prefixErrorBS :: forall e a.
Textual e =>
ByteString -> Either ByteString a -> Either e a
prefixErrorBS = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorBS #-}
prefixErrorBSL
:: Textual e
=> BSL.ByteString
-> Either BSL.ByteString a
-> Either e a
prefixErrorBSL :: forall e a.
Textual e =>
ByteString -> Either ByteString a -> Either e a
prefixErrorBSL = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorBSL #-}
prefixErrorBSB
:: Textual e
=> BSB.Builder
-> Either BSB.Builder a
-> Either e a
prefixErrorBSB :: forall e a. Textual e => Builder -> Either Builder a -> Either e a
prefixErrorBSB = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorBSB #-}
prefixErrorSBS
:: Textual e
=> SBS.ShortByteString
-> Either SBS.ShortByteString a
-> Either e a
prefixErrorSBS :: forall e a.
Textual e =>
ShortByteString -> Either ShortByteString a -> Either e a
prefixErrorSBS = forall e' e a.
(Monoid e', Textual e', Textual e) =>
e' -> Either e' a -> Either e a
prefixError
{-# INLINE prefixErrorSBS #-}
parseEnum
:: (Bounded a, Enum a, Render a, Textual t)
=> Bool
-> Bool
-> e
-> e
-> t
-> Either e a
parseEnum :: forall a t e.
(Bounded a, Enum a, Render a, Textual t) =>
Bool -> Bool -> e -> e -> t -> Either e a
parseEnum Bool
allowCI Bool
allowPrefix e
invalidError e
ambiguousError t
t =
let t' :: Text
t' = Text -> Text
norm forall a b. (a -> b) -> a -> b
$ forall t'. Textual t' => t' -> Text
toT t
t
in case [a
v | a
v <- [forall a. Bounded a => a
minBound ..], Text
t' Text -> Text -> Bool
`match` Text -> Text
norm (forall a t. (Render a, Textual t) => a -> t
render a
v)] of
[a
v] -> forall a b. b -> Either a b
Right a
v
[] -> forall a b. a -> Either a b
Left e
invalidError
[a]
_vs -> forall a b. a -> Either a b
Left e
ambiguousError
where
norm :: T.Text -> T.Text
norm :: Text -> Text
norm = if Bool
allowCI then Text -> Text
T.toLower else forall a. a -> a
id
match :: T.Text -> T.Text -> Bool
match :: Text -> Text -> Bool
match = if Bool
allowPrefix then Text -> Text -> Bool
T.isPrefixOf else forall a. Eq a => a -> a -> Bool
(==)
parseEnum'
:: (Bounded a, Enum a, Render a, Textual t, Textual e)
=> String
-> Bool
-> Bool
-> t
-> Either e a
parseEnum' :: forall a t e.
(Bounded a, Enum a, Render a, Textual t, Textual e) =>
String -> Bool -> Bool -> t -> Either e a
parseEnum' String
name Bool
allowCI Bool
allowPrefix =
forall a t e.
(Bounded a, Enum a, Render a, Textual t) =>
Bool -> Bool -> e -> e -> t -> Either e a
parseEnum
Bool
allowCI Bool
allowPrefix
(forall t. Textual t => String -> t
fromS forall a b. (a -> b) -> a -> b
$ String
"invalid " forall a. [a] -> [a] -> [a]
++ String
name)
(forall t. Textual t => String -> t
fromS forall a b. (a -> b) -> a -> b
$ String
"ambiguous " forall a. [a] -> [a] -> [a]
++ String
name)
{-# INLINEABLE parseEnum' #-}
parseWithRead
:: (Read a, Textual t)
=> e
-> t
-> Either e a
parseWithRead :: forall a t e. (Read a, Textual t) => e -> t -> Either e a
parseWithRead e
invalidError = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. a -> Either a b
Left e
invalidError) forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Read a => String -> Maybe a
readMaybe forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t'. Textual t' => t' -> String
toS
{-# INLINEABLE parseWithRead #-}
parseWithRead'
:: (Read a, Textual t, Textual e)
=> String
-> t
-> Either e a
parseWithRead' :: forall a t e.
(Read a, Textual t, Textual e) =>
String -> t -> Either e a
parseWithRead' String
name = forall a t e. (Read a, Textual t) => e -> t -> Either e a
parseWithRead (forall t. Textual t => String -> t
fromS forall a b. (a -> b) -> a -> b
$ String
"invalid " forall a. [a] -> [a] -> [a]
++ String
name)
{-# INLINEABLE parseWithRead' #-}
maybeParseWithRead
:: (Read a, Textual t)
=> t
-> Maybe a
maybeParseWithRead :: forall a t. (Read a, Textual t) => t -> Maybe a
maybeParseWithRead = forall a. Read a => String -> Maybe a
readMaybe forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t'. Textual t' => t' -> String
toS
readsEnum
:: (Bounded a, Enum a, Render a)
=> Bool
-> Bool
-> ReadS a
readsEnum :: forall a. (Bounded a, Enum a, Render a) => Bool -> Bool -> ReadS a
readsEnum Bool
allowCI Bool
allowPrefix String
s =
case forall a t e.
(Bounded a, Enum a, Render a, Textual t) =>
Bool -> Bool -> e -> e -> t -> Either e a
parseEnum Bool
allowCI Bool
allowPrefix () () String
s of
Right a
v -> [(a
v, String
"")]
Left{} -> []
{-# INLINEABLE readsEnum #-}
readsWithParse
:: Parse a
=> ReadS a
readsWithParse :: forall a. Parse a => ReadS a
readsWithParse String
s = case forall a t. (Parse a, Textual t) => t -> Maybe a
parseMaybe String
s of
Just a
v -> [(a
v, String
"")]
Maybe a
Nothing -> []
{-# INLINEABLE readsWithParse #-}
#if __GLASGOW_HASKELL__ >= 900
valid
:: (MonadFail m, THS.Quote m, Parse a, THS.Lift a)
=> String
-> THS.Code m a
valid :: forall (m :: * -> *) a.
(MonadFail m, Quote m, Parse a, Lift a) =>
String -> Code m a
valid String
s = case forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse String
s of
Right a
x -> [|| x ||]
Left String
err -> forall (m :: * -> *) a. m (TExp a) -> Code m a
THS.Code forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Invalid constant: " forall a. [a] -> [a] -> [a]
++ String
err
#else
valid
:: (Parse a, THS.Lift a)
=> String
-> TH.Q (TH.TExp a)
valid s = case parse s of
Right x -> [|| x ||]
Left err -> fail $ "Invalid constant: " ++ err
#endif
#if __GLASGOW_HASKELL__ >= 900
instance (MonadFail m, THS.Quote m, Parse a, THS.Lift a)
=> IsString (THS.Code m a) where
fromString :: String -> Code m a
fromString = forall (m :: * -> *) a.
(MonadFail m, Quote m, Parse a, Lift a) =>
String -> Code m a
valid
#else
instance (Parse a, THS.Lift a) => IsString (TH.Q (TH.TExp a)) where
fromString = valid
#endif
#if __GLASGOW_HASKELL__ >= 900
validOf
:: (MonadFail m, THS.Quote m, Parse a)
=> Proxy a
-> String
-> THS.Code m a
validOf :: forall (m :: * -> *) a.
(MonadFail m, Quote m, Parse a) =>
Proxy a -> String -> Code m a
validOf Proxy a
proxy String
s = case (forall a (proxy :: * -> *). a -> proxy a -> a
`asProxyTypeOf` Proxy a
proxy) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse String
s of
Right{} -> [|| parseUnsafeS s ||]
Left String
err -> forall (m :: * -> *) a. m (TExp a) -> Code m a
THS.Code forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Invalid constant: " forall a. [a] -> [a] -> [a]
++ String
err
#else
validOf
:: Parse a
=> Proxy a
-> String
-> TH.Q (TH.TExp a)
validOf proxy s = case (`asProxyTypeOf` proxy) <$> parse s of
Right{} -> [|| parseUnsafeS s ||]
Left err -> fail $ "Invalid constant: " ++ err
#endif
mkValid
:: String
-> TH.Name
-> TH.DecsQ
mkValid :: String -> Name -> DecsQ
mkValid String
funName Name
typeName = do
let funName' :: Name
funName' = String -> Name
TH.mkName String
funName
resultType :: Q Type
resultType = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Name -> Type
TH.ConT Name
typeName
#if __GLASGOW_HASKELL__ >= 900
Type
funType <-
[t|
forall m . (MonadFail m, THS.Quote m) =>
String -> THS.Code m $resultType
|]
#else
funType <- [t| String -> TH.Q (TH.TExp $resultType) |]
#endif
Exp
body <- [| validOf (Proxy :: Proxy $resultType) |]
forall (m :: * -> *) a. Monad m => a -> m a
return
[ Name -> Type -> Dec
TH.SigD Name
funName' Type
funType
, Name -> [Clause] -> Dec
TH.FunD Name
funName' [[Pat] -> Body -> [Dec] -> Clause
TH.Clause [] (Exp -> Body
TH.NormalB Exp
body) []]
]
untypedValidOf
:: Parse a
=> Proxy a
-> String
-> TH.ExpQ
untypedValidOf :: forall a. Parse a => Proxy a -> String -> ExpQ
untypedValidOf Proxy a
proxy String
s = case (forall a (proxy :: * -> *). a -> proxy a -> a
`asProxyTypeOf` Proxy a
proxy) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a t e. (Parse a, Textual t, Textual e) => t -> Either e a
parse String
s of
Right{} -> [| parseUnsafeS s |]
Left String
err -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Invalid constant: " forall a. [a] -> [a] -> [a]
++ String
err
mkUntypedValid
:: String
-> TH.Name
-> TH.DecsQ
mkUntypedValid :: String -> Name -> DecsQ
mkUntypedValid String
funName Name
typeName = do
let funName' :: Name
funName' = String -> Name
TH.mkName String
funName
resultType :: Q Type
resultType = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Name -> Type
TH.ConT Name
typeName
Type
funType <- [t| String -> TH.ExpQ |]
Exp
body <- [| untypedValidOf (Proxy :: Proxy $resultType) |]
forall (m :: * -> *) a. Monad m => a -> m a
return
[ Name -> Type -> Dec
TH.SigD Name
funName' Type
funType
, Name -> [Clause] -> Dec
TH.FunD Name
funName' [[Pat] -> Body -> [Dec] -> Clause
TH.Clause [] (Exp -> Body
TH.NormalB Exp
body) []]
]
mkUntypedValidQQ
:: String
-> TH.Name
-> TH.DecsQ
mkUntypedValidQQ :: String -> Name -> DecsQ
mkUntypedValidQQ String
funName Name
typeName = do
let funName' :: Name
funName' = String -> Name
TH.mkName String
funName
resultType :: Q Type
resultType = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Name -> Type
TH.ConT Name
typeName
Exp
expE <- [| untypedValidOf (Proxy :: Proxy $resultType) |]
Exp
expP <- [| error "pattern not supported" |]
Exp
expT <- [| error "type not supported" |]
Exp
expD <- [| error "declaration not supported" |]
let body :: Body
body = Exp -> Body
TH.NormalB forall a b. (a -> b) -> a -> b
$ Name -> [FieldExp] -> Exp
TH.RecConE 'Q.QuasiQuoter
[ ('Q.quoteExp, Exp
expE)
, ('Q.quotePat, Exp
expP)
, ('Q.quoteType, Exp
expT)
, ('Q.quoteDec, Exp
expD)
]
forall (m :: * -> *) a. Monad m => a -> m a
return
[ Name -> Type -> Dec
TH.SigD Name
funName' forall a b. (a -> b) -> a -> b
$ Name -> Type
TH.ConT ''Q.QuasiQuoter
, Name -> [Clause] -> Dec
TH.FunD Name
funName' [[Pat] -> Body -> [Dec] -> Clause
TH.Clause [] Body
body []]
]