From 123f573ab444d11478125a8a122b446e2388a6fe Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Wed, 4 Feb 2015 07:17:32 +0530
Subject: [PATCH] WIP: just experimenting

---
 src/Bencode.hs | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/Bencode.hs b/src/Bencode.hs
index 951f4f1..d6b5740 100644
--- a/src/Bencode.hs
+++ b/src/Bencode.hs
@@ -5,6 +5,7 @@ import qualified Data.ByteString.Char8 as BC
 import qualified Data.Map as M
 import qualified Text.Parsec.ByteString as ParsecBS
 import Text.ParserCombinators.Parsec
+import Text.ParserCombinators.Parsec.Char
 import Control.Applicative ((<*))
 import Data.Functor
 
@@ -25,14 +26,25 @@ data BVal =
 -- Right ""
 -- >>> parse bencStr "Bstr" (BC.pack "0:hello")
 -- Right ""
+--
 bencStr :: ParsecBS.Parser BC.ByteString
 bencStr = do _ <- spaces
              ds <- many1 digit <* char ':'
              s <- count (read ds) anyChar
              return (BC.pack s)
 
+bencInt :: ParsecBS.Parser Integer
+bencInt = do _ <- spaces
+             ds <- between (char 'i') (char 'e') numbers1
+             return (read ds)
+               where numbers = do sign <- option ' ' (try (char '-'))
+                                  ds' <- many1 digit
+                                  return (sign : ds')
+                     numbers1 = many1 anyChar
+
 bencParser :: ParsecBS.Parser BVal
-bencParser = Bstr <$> bencStr
+bencParser = Bstr <$> bencStr <|>
+             Bint <$> bencInt
 
 decode :: BC.ByteString -> Either ParseError BVal
 decode = parse bencParser "BVal"
-- 
2.45.2