]> Git — Sourcephile - haskell/symantic-parser.git/blob - parsers/Parsers/Utils.hs
add registers
[haskell/symantic-parser.git] / parsers / Parsers / Utils.hs
1 module Parsers.Utils
2 ( module Parsers.Utils
3 , w2c
4 )
5 where
6
7 import Data.Char (Char)
8 import Data.Function ((.), id)
9 import Data.Word (Word8)
10 import Prelude (Enum(..))
11 import Data.ByteString.Internal (w2c, c2w)
12
13 -- * Class 'CoerceEnum'
14 -- | Convenient helper to write generic grammars
15 -- consuming either 'Word8' or 'Char'.
16 class CoerceEnum a b where
17 coerceEnum :: a -> b
18 default coerceEnum :: Enum a => Enum b => a -> b
19 coerceEnum = toEnum . fromEnum
20 instance CoerceEnum Word8 Char where
21 coerceEnum = w2c
22 instance CoerceEnum Char Word8 where
23 coerceEnum = c2w
24 instance CoerceEnum Char Char where
25 coerceEnum = id