module Parsers.Utils
  ( module Parsers.Utils
  , w2c
  )
  where

import Data.Char (Char)
import Data.Function ((.), id)
import Data.Word (Word8)
import Prelude (Enum(..))
import Data.ByteString.Internal (w2c, c2w)

-- * Class 'CoerceEnum'
-- | Convenient helper to write generic grammars
-- consuming either 'Word8' or 'Char'.
class CoerceEnum a b where
  coerceEnum :: a -> b
  default coerceEnum :: Enum a => Enum b => a -> b
  coerceEnum = Int -> b
forall a. Enum a => Int -> a
toEnum (Int -> b) -> (a -> Int) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
forall a. Enum a => a -> Int
fromEnum
instance CoerceEnum Word8 Char where
  coerceEnum :: Word8 -> Char
coerceEnum = Word8 -> Char
w2c
instance CoerceEnum Char Word8 where
  coerceEnum :: Char -> Word8
coerceEnum = Char -> Word8
c2w
instance CoerceEnum Char Char where
  coerceEnum :: Char -> Char
coerceEnum = Char -> Char
forall a. a -> a
id