-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Parsers and printers for bencoded data.
--   
--   Parsers and printers 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.
@package bencode
@version 0.6.1.1

module Data.BEncode.Lexer
data Token
TDict :: Token
TList :: Token
TInt :: Token
TString :: ByteString -> Token
TNumber :: Integer -> Token
TEnd :: Token
lexer :: ByteString -> [Token]
instance GHC.Classes.Eq Data.BEncode.Lexer.Token
instance GHC.Internal.Show.Show Data.BEncode.Lexer.Token

-- | Provides a BEncode data type is well as functions for converting this
--   data type to and from a String.
--   
--   Also supplies a number of properties which the module must satisfy.
module Data.BEncode

-- | The B-coding defines an abstract syntax tree given as a simple data
--   type here
data BEncode
BInt :: Integer -> BEncode
BString :: ByteString -> BEncode
BList :: [BEncode] -> BEncode
BDict :: Map String BEncode -> BEncode

-- | bRead is a conversion routine. It assumes a B-coded string as input
--   and attempts a parse of it into a BEncode data type
bRead :: ByteString -> Maybe BEncode

-- | Render a BEncode structure to a B-coded string
bShow :: BEncode -> ShowS
bPack :: BEncode -> ByteString
instance Data.Binary.Class.Binary Data.BEncode.BEncode
instance GHC.Classes.Eq Data.BEncode.BEncode
instance GHC.Classes.Ord Data.BEncode.BEncode
instance GHC.Internal.Show.Show Data.BEncode.BEncode

-- | A parsec style parser for BEncoded data

-- | Deprecated: Use Data.BEncode.Reader instead
module Data.BEncode.Parser
data BParser a
runParser :: BParser a -> BEncode -> Either String a
token :: BParser BEncode
dict :: String -> BParser BEncode
list :: String -> BParser a -> BParser [a]
optional :: BParser a -> BParser (Maybe a)
bstring :: BParser BEncode -> BParser String
bbytestring :: BParser BEncode -> BParser ByteString
bint :: BParser BEncode -> BParser Integer
setInput :: BEncode -> BParser ()

-- | An associative binary operation
(<|>) :: Alternative f => f a -> f a -> f a
infixl 3 <|>
instance GHC.Internal.Base.Alternative Data.BEncode.Parser.BParser
instance GHC.Internal.Base.Applicative Data.BEncode.Parser.BParser
instance GHC.Internal.Base.Functor Data.BEncode.Parser.BParser
instance GHC.Internal.Base.Monad Data.BEncode.Parser.BParser
instance GHC.Internal.Control.Monad.Fail.MonadFail Data.BEncode.Parser.BParser
instance GHC.Internal.Base.MonadPlus Data.BEncode.Parser.BParser

-- | Reader monad and combinators for BEncoded data.
--   
--   This is intended to replace the older Data.BEncode.Parser
--   module.
--   
--   Usage example:
--   
--   
--   >>> :set -XOverloadedStrings
--   
--   >>> let bd = (BDict $ Map.fromList [("baz", BInt 1), ("foo", BString "bar")])
--   
--   >>> :{
--   let bReader = do
--         baz <- dict "baz" bint
--         foo <- dict "foo" bstring
--         shouldBeNothing <- optional $ dict "optionalKey" bint
--         return (foo, baz, shouldBeNothing)
--   in runBReader bReader bd
--   :}
--   Right ("bar",1,Nothing)
--   
module Data.BEncode.Reader

-- | Reader monad for extracting data from a BEncoded structure.
data BReader a

-- | Run a BReader. See usage examples elsewhere in this file.
runBReader :: BReader a -> BEncode -> Either String a

-- | 
--   >>> runBReader bint (BInt 42)
--   Right 42
--   
bint :: BReader Integer

-- | Usage same as bstring, below. (sadly, doctests for this cause errors
--   on GHC 7.4)
bbytestring :: BReader ByteString

-- | 
--   >>> runBReader bstring (BString "foo")
--   Right "foo"
--   
bstring :: BReader String

-- | One or none.
--   
--   It is useful for modelling any computation that is allowed to fail.
--   
--   
Examples
--   
--   Using the Alternative instance of Control.Monad.Except,
--   the following functions:
--   
--   
--   >>> import Control.Monad.Except
--   
--   
--   
--   >>> canFail = throwError "it failed" :: Except String Int
--   
--   >>> final = return 42                :: Except String Int
--   
--   
--   Can be combined by allowing the first function to fail:
--   
--   
--   >>> runExcept $ canFail *> final
--   Left "it failed"
--   
--   
--   
--   >>> runExcept $ optional canFail *> final
--   Right 42
--   
optional :: Alternative f => f a -> f (Maybe a)

-- | Read a list of BEncoded data
--   
--   
--   >>> runBReader (list bint) (BList [BInt 1, BInt 2])
--   Right [1,2]
--   
--   
--   
--   >>> runBReader (list bint) (BList [])
--   Right []
--   
--   
--   
--   >>> let bs = (BList [BList [BString "foo", BString "bar"], BList []])
--   
--   >>> runBReader (list $ list bstring) bs
--   Right [["foo","bar"],[]]
--   
list :: BReader a -> BReader [a]

-- | Read the values of a BDict corresponding to a string key
--   
--   
--   >>> let bd = (BDict $ Map.fromList [("bar", BInt 2), ("foo", BInt 1)])
--   
--   >>> runBReader (dict "foo" bint) bd
--   Right 1
--   
--   
--   
--   >>> :{
--   let bs = (BList [BDict $ Map.fromList [("baz", BInt 2),
--                                          ("foo", BString "bar")],
--                    BDict $ Map.singleton "foo" (BString "bam")])
--   in runBReader (list $ dict "foo" bstring) bs
--   :}
--   Right ["bar","bam"]
--   
--   
--   
--   >>> :{
--   let bd = (BDict $ Map.singleton "foo" (BList [
--               BString "foo", BString "bar"
--            ]))
--   in runBReader (dict "foo" $ list $ bstring) bd
--   :}
--   Right ["foo","bar"]
--   
dict :: String -> BReader a -> BReader a
instance GHC.Internal.Base.Alternative Data.BEncode.Reader.BReader
instance GHC.Internal.Base.Applicative Data.BEncode.Reader.BReader
instance GHC.Internal.Base.Functor Data.BEncode.Reader.BReader
instance GHC.Internal.Base.Monad Data.BEncode.Reader.BReader
instance GHC.Internal.Base.MonadPlus Data.BEncode.Reader.BReader
