packages feed

bencode 0.5.0.1 → 0.6.0.0

raw patch · 3 files changed

+57/−31 lines, 3 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Data.BEncode.Parser: instance Alternative BParser
+ Data.BEncode.Parser: instance Applicative BParser
- Data.BEncode.Parser: (<|>) :: BParser a -> BParser a -> BParser a
+ Data.BEncode.Parser: (<|>) :: Alternative f => forall a. f a -> f a -> f a

Files

bencode.cabal view
@@ -1,21 +1,40 @@ Name:            bencode-Version:         0.5.0.1-Maintainer:      Lemmih (lemmih@gmail.com)+Version:         0.6.0.0+Maintainer:      Christopher Reichert <creichert07@gmail.com> Author:          Lemmih (lemmih@gmail.com), Jesper Louis Andersen-Copyright:       (c) 2005-2009, David Himmelstrup-                     2006 Lemmih <lemmih@gmail.com>+Copyright:       (c) 2005-2009, David Himmelstrup,+                     2006 Lemmih <lemmih@gmail.com>,                      2005 Jesper Louis Andersen <jlouis@mongers.org> License-File:    LICENSE License:         BSD3-Build-Depends:   base<5, parsec, bytestring, containers, binary Build-Type:      Simple Category:        Text+Tested-With:     GHC == 7.10.1, GHC == 7.8.4, GHC == 7.8.3, GHC == 7.6.3+Cabal-Version:   >= 1.10 Synopsis:        Parser and printer for bencoded data.-Tested-with:     GHC ==6.8.1, GHC ==6.10.2-Extensions:      PatternGuards-Exposed-Modules:-  Data.BEncode-  Data.BEncode.Lexer-  Data.BEncode.Parser-GHC-Options:     -Wall-Hs-Source-Dirs:  src+Description:+  Parser and printer for bencoded data.+  .+  Bencode (pronounced like B encode) is the encoding used by the+  peer-to-peer file sharing system BitTorrent for storing and+  transmitting loosely structured data.+++Source-Repository head+  type:     git+  location: https://github.com/creichert/bencode+++Library+  GHC-Options:        -Wall+  Default-Extensions: PatternGuards+  Hs-Source-Dirs:     src+  Default-Language:   Haskell2010+  Exposed-Modules:    Data.BEncode+                      Data.BEncode.Lexer+                      Data.BEncode.Parser+  Build-Depends:      base<5+                    , parsec+                    , bytestring+                    , containers+                    , binary
src/Data/BEncode.hs view
@@ -41,10 +41,10 @@      data type here -} data BEncode = BInt Integer-	     | BString L.ByteString-	     | BList [BEncode]+             | BString L.ByteString+             | BList [BEncode]              | BDict (Map String BEncode)-	       deriving (Eq, Ord, Show)+               deriving (Eq, Ord, Show)  instance Binary BEncode where     put e = put (BS.concat $ L.toChunks $ bPack e)@@ -93,9 +93,9 @@  bDict :: BParser BEncode bDict = withToken TDict $ fmap (BDict . Map.fromAscList) (checkList =<< many1 bAssocList)-    where checkList lst = if (lst /= sort lst)-                          then fail "dictionary not sorted"-                          else return lst+    where checkList lst = if lst /= sort lst+                            then fail "dictionary not sorted"+                            else return lst           bAssocList               = do str <- tstring                    value <- bParse@@ -109,18 +109,18 @@ -} bRead :: L.ByteString -> Maybe BEncode bRead str = case parse bParse "" (lexer str) of-	     Left _err -> Nothing-	     Right b   -> Just b+              Left _err -> Nothing+              Right b   -> Just b  -- | Render a BEncode structure to a B-coded string bShow :: BEncode -> ShowS-bShow be = bShow' be+bShow = bShow'   where     sc = showChar     ss = showString     sKV (k,v) = sString k (length k) . bShow' v-    sDict dict = foldr (.) id (map sKV (Map.toAscList dict))-    sList list = foldr (.) id (map bShow' list)+    sDict dict = foldr ((.) . sKV) id (Map.toAscList dict)+    sList = foldr ((.) . bShow') id     sString str len = shows len . sc ':' . ss str     bShow' b =       case b of
src/Data/BEncode/Parser.hs view
@@ -24,14 +24,19 @@     ) where  -import Data.BEncode-import qualified Data.Map as Map+import           Control.Applicative        hiding (optional)+import           Control.Monad+import           Data.BEncode import qualified Data.ByteString.Lazy.Char8 as L-import Control.Monad+import qualified Data.Map                   as Map  data BParser a     = BParser (BEncode -> Reply a) +instance Alternative BParser where+    empty = mzero+    (<|>) a b = a `mplus` b+ instance MonadPlus BParser where     mzero = BParser $ \_ -> Error "mzero"     mplus (BParser a) (BParser b) = BParser $ \st -> case a st of@@ -46,6 +51,11 @@     = Ok a BEncode     | Error String ++instance Applicative BParser where+  pure = return+  (<*>) = ap+ instance Monad BParser where     (BParser p) >>= f = BParser $ \b -> case p b of                                           Ok a b' -> runB (f a) b'@@ -57,9 +67,6 @@     fmap fn p = do a <- p                    return (fn a) -(<|>) :: BParser a -> BParser a -> BParser a-a <|> b = a `mplus` b- runParser :: BParser a -> BEncode -> Either String a runParser parser b = case runB parser b of                        Ok a _ -> Right a@@ -79,7 +86,7 @@ list name p     = dict name >>= \lst ->       BParser $ \b -> case lst of-                      BList bs -> foldr cat (Ok [] b) (map (runB p) bs)+                      BList bs -> foldr (cat . runB p) (Ok [] b) bs                       _ -> Error $ "Not a list: " ++ name     where cat (Ok v _) (Ok vs b) = Ok (v:vs) b           cat (Ok _ _) (Error str) = Error str