]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Chunk.hs
The attoparsec branch. It doesn't even compile for now.
[Lucu.git] / Network / HTTP / Lucu / Chunk.hs
index 44f2ae4c16890bc3df3b4064938c378335d2af9c..a419464eefbc322989141167b8d4cbf8bcc741db 100644 (file)
@@ -1,36 +1,35 @@
--- #hide
+{-# LANGUAGE
+    UnicodeSyntax
+  #-}
 module Network.HTTP.Lucu.Chunk
     ( chunkHeaderP  -- Num a => Parser a
     , chunkFooterP  -- Parser ()
     , chunkTrailerP -- Parser Headers
     )
     where
-
-import           Network.HTTP.Lucu.Headers
-import           Network.HTTP.Lucu.Parser
-import           Network.HTTP.Lucu.Parser.Http
-import           Numeric
-
-
-chunkHeaderP :: Num a => Parser a
-chunkHeaderP = do hexLen <- many1 hexDigit
+import Control.Applicative
+import Data.Attoparsec.Char8
+import Data.Bits
+import Network.HTTP.Lucu.Headers
+import Network.HTTP.Lucu.Parser.Http
+
+chunkHeaderP ∷ (Integral a, Bits a) ⇒ Parser a
+{-# INLINEABLE chunkHeaderP #-}
+chunkHeaderP = do len ← hexadecimal
                   extension
                   crlf
-
-                  let [(len, _)] = readHex hexLen
                   return len
     where
-      extension :: Parser ()
-      extension = do many $ do char ';'
-                               token
-                               char '='
-                               token <|> quotedStr
+      extension ∷ Parser ()
+      extension = skipMany $
+                  do _ ← char ';'
+                     _ ← token
+                     _ ← char '='
+                     _ ← token <|> quotedStr
                      return ()
 
+chunkFooterP ∷ Parser ()
+chunkFooterP = crlf
 
-chunkFooterP :: Parser ()
-chunkFooterP = crlf >> return ()
-
-
-chunkTrailerP :: Parser Headers
+chunkTrailerP ∷ Parser Headers
 chunkTrailerP = headersP