]> gitweb @ CieloNegro.org - Lucu.git/blob - Data/Attoparsec/Parsable.hs
d801fb7b3eee1bb066c1348f111c77ba9290aff1
[Lucu.git] / Data / Attoparsec / Parsable.hs
1 {-# LANGUAGE MultiParamTypeClasses #-}
2 module Data.Attoparsec.Parsable
3     ( Parsable(..)
4     )
5     where
6 import qualified Data.Attoparsec.ByteString as B
7 import qualified Data.Attoparsec.ByteString.Char8 as B
8 import qualified Data.Attoparsec.Text as T
9 import Data.Attoparsec.Number
10 import Data.Attoparsec.Types
11 import qualified Data.ByteString as B
12 import qualified Data.ByteString.Lazy as LB
13 import qualified Data.Text as T
14 import qualified Data.Text.Lazy as LT
15 import Data.Word
16
17 -- |Class of types which have their corresponding parsers.
18 --
19 -- Minimal complete definition: 'parser'
20 class Parsable t a where
21     parser :: Parser t a
22
23 instance Parsable B.ByteString Word8 where
24     {-# INLINE CONLIKE parser #-}
25     parser = B.anyWord8
26
27 instance Parsable B.ByteString Char where
28     {-# INLINE CONLIKE parser #-}
29     parser = B.anyChar
30
31 instance Parsable B.ByteString B.ByteString where
32     {-# INLINE CONLIKE parser #-}
33     parser = B.takeByteString
34
35 instance Parsable B.ByteString LB.ByteString where
36     {-# INLINE CONLIKE parser #-}
37     parser = B.takeLazyByteString
38
39 instance Parsable B.ByteString Double where
40     {-# INLINE CONLIKE parser #-}
41     parser = B.double
42
43 instance Parsable B.ByteString Number where
44     {-# INLINE CONLIKE parser #-}
45     parser = B.number
46
47 instance Parsable T.Text Char where
48     {-# INLINE CONLIKE parser #-}
49     parser = T.anyChar
50
51 instance Parsable T.Text T.Text where
52     {-# INLINE CONLIKE parser #-}
53     parser = T.takeText
54
55 instance Parsable T.Text LT.Text where
56     {-# INLINE CONLIKE parser #-}
57     parser = T.takeLazyText
58
59 instance Parsable T.Text Double where
60     {-# INLINE CONLIKE parser #-}
61     parser = T.double
62
63 instance Parsable T.Text Number where
64     {-# INLINE CONLIKE parser #-}
65     parser = T.number