{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}

module Text.Appar.Input where

import qualified Data.ByteString.Char8 as S
import qualified Data.ByteString.Lazy.Char8 as L

----------------------------------------------------------------

{-|
  The class for parser input.
-}
class Eq inp => Input inp where
    -- | The head function for input
    car :: inp -> Char
    -- | The tail function for input
    cdr :: inp -> inp
    -- | The end of input
    nil :: inp
    -- | The function to check the end of input
    isNil :: inp -> Bool


instance Input S.ByteString where
    car :: ByteString -> Char
car   = ByteString -> Char
S.head
    cdr :: ByteString -> ByteString
cdr   = HasCallStack => ByteString -> ByteString
ByteString -> ByteString
S.tail
    nil :: ByteString
nil   = ByteString
S.empty
    isNil :: ByteString -> Bool
isNil = ByteString -> Bool
S.null

instance Input L.ByteString where
    car :: ByteString -> Char
car   = ByteString -> Char
L.head
    cdr :: ByteString -> ByteString
cdr   = HasCallStack => ByteString -> ByteString
ByteString -> ByteString
L.tail
    nil :: ByteString
nil   = ByteString
L.empty
    isNil :: ByteString -> Bool
isNil = ByteString -> Bool
L.null

instance Input String where
    car :: String -> Char
car = String -> Char
forall a. HasCallStack => [a] -> a
head
    cdr :: String -> String
cdr = String -> String
forall a. HasCallStack => [a] -> [a]
tail
    isNil :: String -> Bool
isNil = String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null
    nil :: String
nil = String
""