{-# LANGUAGE CPP                #-}
{-# LANGUAGE DeriveAnyClass     #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE FlexibleInstances  #-}

-- | Shared types.

module Xeno.Types where

import Control.DeepSeq
import Control.Exception
import Data.ByteString.Char8 (ByteString, pack)
import Data.Data
import GHC.Generics

#if MIN_VERSION_base(4,9,0)
import Control.Monad.Fail

-- It is recommended to use more specific `failHere` instead
instance MonadFail (Either Xeno.Types.XenoException) where
  fail :: String -> Either XenoException a
fail = XenoException -> Either XenoException a
forall a b. a -> Either a b
Left (XenoException -> Either XenoException a)
-> (String -> XenoException) -> String -> Either XenoException a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ByteString -> XenoException
XenoParseError Int
0 (ByteString -> XenoException)
-> (String -> ByteString) -> String -> XenoException
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
pack
#endif

data XenoException
  = XenoStringIndexProblem { XenoException -> Int
stringIndex :: Int, XenoException -> ByteString
inputString :: ByteString }
  | XenoParseError         { XenoException -> Int
inputIndex  :: Int, XenoException -> ByteString
message     :: ByteString }
  | XenoExpectRootNode
  deriving (Int -> XenoException -> ShowS
[XenoException] -> ShowS
XenoException -> String
(Int -> XenoException -> ShowS)
-> (XenoException -> String)
-> ([XenoException] -> ShowS)
-> Show XenoException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [XenoException] -> ShowS
$cshowList :: [XenoException] -> ShowS
show :: XenoException -> String
$cshow :: XenoException -> String
showsPrec :: Int -> XenoException -> ShowS
$cshowsPrec :: Int -> XenoException -> ShowS
Show, Typeable XenoException
DataType
Constr
Typeable XenoException
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> XenoException -> c XenoException)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c XenoException)
-> (XenoException -> Constr)
-> (XenoException -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c XenoException))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c XenoException))
-> ((forall b. Data b => b -> b) -> XenoException -> XenoException)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> XenoException -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> XenoException -> r)
-> (forall u. (forall d. Data d => d -> u) -> XenoException -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> XenoException -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> XenoException -> m XenoException)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> XenoException -> m XenoException)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> XenoException -> m XenoException)
-> Data XenoException
XenoException -> DataType
XenoException -> Constr
(forall b. Data b => b -> b) -> XenoException -> XenoException
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> XenoException -> c XenoException
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c XenoException
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> XenoException -> u
forall u. (forall d. Data d => d -> u) -> XenoException -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> XenoException -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> XenoException -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> XenoException -> m XenoException
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> XenoException -> m XenoException
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c XenoException
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> XenoException -> c XenoException
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c XenoException)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c XenoException)
$cXenoExpectRootNode :: Constr
$cXenoParseError :: Constr
$cXenoStringIndexProblem :: Constr
$tXenoException :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> XenoException -> m XenoException
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> XenoException -> m XenoException
gmapMp :: (forall d. Data d => d -> m d) -> XenoException -> m XenoException
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> XenoException -> m XenoException
gmapM :: (forall d. Data d => d -> m d) -> XenoException -> m XenoException
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> XenoException -> m XenoException
gmapQi :: Int -> (forall d. Data d => d -> u) -> XenoException -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> XenoException -> u
gmapQ :: (forall d. Data d => d -> u) -> XenoException -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> XenoException -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> XenoException -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> XenoException -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> XenoException -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> XenoException -> r
gmapT :: (forall b. Data b => b -> b) -> XenoException -> XenoException
$cgmapT :: (forall b. Data b => b -> b) -> XenoException -> XenoException
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c XenoException)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c XenoException)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c XenoException)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c XenoException)
dataTypeOf :: XenoException -> DataType
$cdataTypeOf :: XenoException -> DataType
toConstr :: XenoException -> Constr
$ctoConstr :: XenoException -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c XenoException
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c XenoException
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> XenoException -> c XenoException
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> XenoException -> c XenoException
$cp1Data :: Typeable XenoException
Data, Typeable, XenoException -> ()
(XenoException -> ()) -> NFData XenoException
forall a. (a -> ()) -> NFData a
rnf :: XenoException -> ()
$crnf :: XenoException -> ()
NFData, (forall x. XenoException -> Rep XenoException x)
-> (forall x. Rep XenoException x -> XenoException)
-> Generic XenoException
forall x. Rep XenoException x -> XenoException
forall x. XenoException -> Rep XenoException x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep XenoException x -> XenoException
$cfrom :: forall x. XenoException -> Rep XenoException x
Generic)

instance Exception XenoException where displayException :: XenoException -> String
displayException = XenoException -> String
forall a. Show a => a -> String
show

-- | ByteString wich guaranted have '\NUL' at the end
newtype ByteStringZeroTerminated = BSZT ByteString deriving ((forall x.
 ByteStringZeroTerminated -> Rep ByteStringZeroTerminated x)
-> (forall x.
    Rep ByteStringZeroTerminated x -> ByteStringZeroTerminated)
-> Generic ByteStringZeroTerminated
forall x.
Rep ByteStringZeroTerminated x -> ByteStringZeroTerminated
forall x.
ByteStringZeroTerminated -> Rep ByteStringZeroTerminated x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ByteStringZeroTerminated x -> ByteStringZeroTerminated
$cfrom :: forall x.
ByteStringZeroTerminated -> Rep ByteStringZeroTerminated x
Generic, ByteStringZeroTerminated -> ()
(ByteStringZeroTerminated -> ()) -> NFData ByteStringZeroTerminated
forall a. (a -> ()) -> NFData a
rnf :: ByteStringZeroTerminated -> ()
$crnf :: ByteStringZeroTerminated -> ()
NFData)