diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-09-29 06:18:18 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-09-29 06:18:18 +0400 |
commit | a7f121250cf9409409ff90f9cedf284bf3cab317 (patch) | |
tree | 1be9d7ca897eb5573d84e74b2ce174600a7cb1a5 | |
parent | 573487ff0d758e1c500c26bc1e8b90dd155eb97b (diff) |
Eliminate list conversion in parsing
-rw-r--r-- | src/Data/BEncode.hs | 10 | ||||
-rw-r--r-- | src/Data/BEncode/BDict.hs | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs index 8858730..086d34f 100644 --- a/src/Data/BEncode.hs +++ b/src/Data/BEncode.hs | |||
@@ -788,13 +788,13 @@ parser = valueP | |||
788 | di | di <= '9' -> BString <$> stringP | 788 | di | di <= '9' -> BString <$> stringP |
789 | 'i' -> P.anyChar *> ((BInteger <$> integerP) <* P.anyChar) | 789 | 'i' -> P.anyChar *> ((BInteger <$> integerP) <* P.anyChar) |
790 | 'l' -> P.anyChar *> ((BList <$> listBody) <* P.anyChar) | 790 | 'l' -> P.anyChar *> ((BList <$> listBody) <* P.anyChar) |
791 | 'd' -> do | 791 | 'd' -> P.anyChar *> (BDict <$> dictBodyP)<* P.anyChar |
792 | P.anyChar | ||
793 | (BDict . BD.fromAscList <$> | ||
794 | many ((,) <$> stringP <*> valueP)) | ||
795 | <* P.anyChar | ||
796 | t -> fail ("bencode unknown tag: " ++ [t]) | 792 | t -> fail ("bencode unknown tag: " ++ [t]) |
797 | 793 | ||
794 | dictBodyP :: Parser BDict | ||
795 | dictBodyP = Cons <$> stringP <*> valueP <*> dictBodyP | ||
796 | <|> pure Nil | ||
797 | |||
798 | listBody = do | 798 | listBody = do |
799 | c <- P.peekChar | 799 | c <- P.peekChar |
800 | case c of | 800 | case c of |
diff --git a/src/Data/BEncode/BDict.hs b/src/Data/BEncode/BDict.hs index c674b21..2b58644 100644 --- a/src/Data/BEncode/BDict.hs +++ b/src/Data/BEncode/BDict.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | module Data.BEncode.BDict | 1 | module Data.BEncode.BDict |
2 | ( BKey | 2 | ( BKey |
3 | , BDictMap | 3 | , BDictMap (..) |
4 | 4 | ||
5 | -- * Construction | 5 | -- * Construction |
6 | , Data.BEncode.BDict.empty | 6 | , Data.BEncode.BDict.empty |