From 2dfd3e662204585dd64f2ddbe3b3eed0c708c68f Mon Sep 17 00:00:00 2001 From: PHO Date: Mon, 19 Dec 2011 22:02:26 +0900 Subject: [PATCH] New file: Parsable.hs Ditz-issue: d23a51590bc111f85646532c9a8538dd04aa20b4 --- Data/Attoparsec/Parsable.hs | 65 +++++++++++++++++++ Lucu.cabal | 1 + Network/HTTP/Lucu/StaticFile.hs | 1 - ...a377be55430e655ab42fdc4902fa56a058b26.yaml | 8 ++- ...a51590bc111f85646532c9a8538dd04aa20b4.yaml | 23 +++++++ 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 Data/Attoparsec/Parsable.hs create mode 100644 bugs/issue-d23a51590bc111f85646532c9a8538dd04aa20b4.yaml diff --git a/Data/Attoparsec/Parsable.hs b/Data/Attoparsec/Parsable.hs new file mode 100644 index 0000000..a991607 --- /dev/null +++ b/Data/Attoparsec/Parsable.hs @@ -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: 'parse' +class Parsable t a where + parse :: Parser t a + +instance Parsable B.ByteString Word8 where + {-# INLINE CONLIKE parse #-} + parse = B.anyWord8 + +instance Parsable B.ByteString Char where + {-# INLINE CONLIKE parse #-} + parse = B.anyChar + +instance Parsable B.ByteString B.ByteString where + {-# INLINE CONLIKE parse #-} + parse = B.takeByteString + +instance Parsable B.ByteString LB.ByteString where + {-# INLINE CONLIKE parse #-} + parse = B.takeLazyByteString + +instance Parsable B.ByteString Double where + {-# INLINE CONLIKE parse #-} + parse = B.double + +instance Parsable B.ByteString Number where + {-# INLINE CONLIKE parse #-} + parse = B.number + +instance Parsable T.Text Char where + {-# INLINE CONLIKE parse #-} + parse = T.anyChar + +instance Parsable T.Text T.Text where + {-# INLINE CONLIKE parse #-} + parse = T.takeText + +instance Parsable T.Text LT.Text where + {-# INLINE CONLIKE parse #-} + parse = T.takeLazyText + +instance Parsable T.Text Double where + {-# INLINE CONLIKE parse #-} + parse = T.double + +instance Parsable T.Text Number where + {-# INLINE CONLIKE parse #-} + parse = T.number diff --git a/Lucu.cabal b/Lucu.cabal index 00f3091..163b9b7 100644 --- a/Lucu.cabal +++ b/Lucu.cabal @@ -88,6 +88,7 @@ Library -DHAVE_SSL Exposed-Modules: + Data.Attoparsec.Parsable Data.Collections.Newtype.TH Network.HTTP.Lucu Network.HTTP.Lucu.Abortion diff --git a/Network/HTTP/Lucu/StaticFile.hs b/Network/HTTP/Lucu/StaticFile.hs index 6dd47af..f560ae3 100644 --- a/Network/HTTP/Lucu/StaticFile.hs +++ b/Network/HTTP/Lucu/StaticFile.hs @@ -19,7 +19,6 @@ import Data.Convertible.Base import Data.Convertible.Instances.Text () import Data.Monoid.Unicode import Data.String -import qualified Data.Text as T import qualified Data.Text.Encoding as T import Network.HTTP.Lucu.Abortion import Network.HTTP.Lucu.Config diff --git a/bugs/issue-0a2a377be55430e655ab42fdc4902fa56a058b26.yaml b/bugs/issue-0a2a377be55430e655ab42fdc4902fa56a058b26.yaml index 79fa84b..808055c 100644 --- a/bugs/issue-0a2a377be55430e655ab42fdc4902fa56a058b26.yaml +++ b/bugs/issue-0a2a377be55430e655ab42fdc4902fa56a058b26.yaml @@ -5,8 +5,8 @@ type: :task component: Lucu release: Lucu-1.0 reporter: PHO -status: :in_progress -disposition: +status: :closed +disposition: :fixed creation_time: 2011-12-14 14:07:41.367770 Z references: [] @@ -24,4 +24,8 @@ log_events: - PHO - changed status from unstarted to in_progress - "" +- - 2011-12-19 13:00:36.705779 Z + - PHO + - closed with disposition fixed + - Done. git_branch: diff --git a/bugs/issue-d23a51590bc111f85646532c9a8538dd04aa20b4.yaml b/bugs/issue-d23a51590bc111f85646532c9a8538dd04aa20b4.yaml new file mode 100644 index 0000000..d33391b --- /dev/null +++ b/bugs/issue-d23a51590bc111f85646532c9a8538dd04aa20b4.yaml @@ -0,0 +1,23 @@ +--- !ditz.rubyforge.org,2008-03-06/issue +title: Introduce 'Parsable' type class +desc: I'll send a pull request to bos/attoparsec when it's ready. +type: :task +component: Lucu +release: Lucu-1.0 +reporter: PHO +status: :in_progress +disposition: +creation_time: 2011-12-19 13:01:51.401625 Z +references: [] + +id: d23a51590bc111f85646532c9a8538dd04aa20b4 +log_events: +- - 2011-12-19 13:01:52.375925 Z + - PHO + - created + - "" +- - 2011-12-19 13:02:07.064863 Z + - PHO + - changed status from unstarted to in_progress + - "" +git_branch: -- 2.40.0