]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Data/Attoparsec/Parsable.hs
Merge branch 'parsable'
[Lucu.git] / Data / Attoparsec / Parsable.hs
diff --git a/Data/Attoparsec/Parsable.hs b/Data/Attoparsec/Parsable.hs
new file mode 100644 (file)
index 0000000..d801fb7
--- /dev/null
@@ -0,0 +1,65 @@
+{-# LANGUAGE MultiParamTypeClasses #-}
+module Data.Attoparsec.Parsable
+    ( Parsable(..)
+    )
+    where
+import qualified Data.Attoparsec.ByteString as B
+import qualified Data.Attoparsec.ByteString.Char8 as B
+import qualified Data.Attoparsec.Text as T
+import Data.Attoparsec.Number
+import Data.Attoparsec.Types
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Lazy as LB
+import qualified Data.Text as T
+import qualified Data.Text.Lazy as LT
+import Data.Word
+
+-- |Class of types which have their corresponding parsers.
+--
+-- Minimal complete definition: 'parser'
+class Parsable t a where
+    parser :: Parser t a
+
+instance Parsable B.ByteString Word8 where
+    {-# INLINE CONLIKE parser #-}
+    parser = B.anyWord8
+
+instance Parsable B.ByteString Char where
+    {-# INLINE CONLIKE parser #-}
+    parser = B.anyChar
+
+instance Parsable B.ByteString B.ByteString where
+    {-# INLINE CONLIKE parser #-}
+    parser = B.takeByteString
+
+instance Parsable B.ByteString LB.ByteString where
+    {-# INLINE CONLIKE parser #-}
+    parser = B.takeLazyByteString
+
+instance Parsable B.ByteString Double where
+    {-# INLINE CONLIKE parser #-}
+    parser = B.double
+
+instance Parsable B.ByteString Number where
+    {-# INLINE CONLIKE parser #-}
+    parser = B.number
+
+instance Parsable T.Text Char where
+    {-# INLINE CONLIKE parser #-}
+    parser = T.anyChar
+
+instance Parsable T.Text T.Text where
+    {-# INLINE CONLIKE parser #-}
+    parser = T.takeText
+
+instance Parsable T.Text LT.Text where
+    {-# INLINE CONLIKE parser #-}
+    parser = T.takeLazyText
+
+instance Parsable T.Text Double where
+    {-# INLINE CONLIKE parser #-}
+    parser = T.double
+
+instance Parsable T.Text Number where
+    {-# INLINE CONLIKE parser #-}
+    parser = T.number