diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-06-02 07:04:34 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-06-02 07:04:34 +0400 |
commit | 8deb9ec7c7d500daa3e84a92de02ae205ada7433 (patch) | |
tree | 61beb2b1021e9c314a72950f1e6527f4172df142 /src | |
parent | 665c7fe8e106c2920323586cedbdd52f8db09b0f (diff) |
~ Use pretty package instead of ansi-wl-pprint.
Because it's already included core libraries in and we do not need all
those things provided by ansi-wl-pprint.
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/BEncode.hs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs index 5097fe8..953fda3 100644 --- a/src/Data/BEncode.hs +++ b/src/Data/BEncode.hs | |||
@@ -42,6 +42,7 @@ | |||
42 | -- This module is considered to be imported qualified. | 42 | -- This module is considered to be imported qualified. |
43 | -- | 43 | -- |
44 | {-# LANGUAGE FlexibleInstances #-} | 44 | {-# LANGUAGE FlexibleInstances #-} |
45 | {-# LANGUAGE Trustworthy #-} | ||
45 | module Data.BEncode | 46 | module Data.BEncode |
46 | ( -- * Datatype | 47 | ( -- * Datatype |
47 | BEncode(..) | 48 | BEncode(..) |
@@ -92,10 +93,11 @@ import qualified Data.ByteString.Builder.Prim as BP (int64Dec, primBounded) | |||
92 | import Data.Text (Text) | 93 | import Data.Text (Text) |
93 | import qualified Data.Text.Encoding as T | 94 | import qualified Data.Text.Encoding as T |
94 | import Data.Version | 95 | import Data.Version |
95 | import Text.PrettyPrint.ANSI.Leijen (Pretty, Doc, pretty, (<+>), (</>)) | 96 | import Text.PrettyPrint hiding ((<>)) |
96 | import qualified Text.PrettyPrint.ANSI.Leijen as PP | ||
97 | import qualified Text.ParserCombinators.ReadP as ReadP | 97 | import qualified Text.ParserCombinators.ReadP as ReadP |
98 | 98 | ||
99 | |||
100 | |||
99 | type Dict = Map ByteString BEncode | 101 | type Dict = Map ByteString BEncode |
100 | 102 | ||
101 | -- | 'BEncode' is straightforward ADT for b-encoded values. | 103 | -- | 'BEncode' is straightforward ADT for b-encoded values. |
@@ -432,23 +434,18 @@ parser = valueP | |||
432 | 434 | ||
433 | -------------------------------- pretty printing ------------------------------- | 435 | -------------------------------- pretty printing ------------------------------- |
434 | printPretty :: BEncode -> IO () | 436 | printPretty :: BEncode -> IO () |
435 | printPretty = print . pretty | 437 | printPretty = print . ppBEncode |
436 | 438 | ||
437 | ppBS :: ByteString -> Doc | 439 | ppBS :: ByteString -> Doc |
438 | ppBS = PP.string . map w2c . B.unpack | 440 | ppBS = text . map w2c . B.unpack |
439 | 441 | ||
440 | instance Pretty BEncode where | 442 | ppBEncode :: BEncode -> Doc |
441 | pretty (BInteger i) = PP.integer (fromIntegral i) | 443 | ppBEncode (BInteger i) = int (fromIntegral i) |
442 | pretty (BString s) = ppBS s | 444 | ppBEncode (BString s) = ppBS s |
443 | pretty (BList l) = PP.lbracket <+> | 445 | ppBEncode (BList l) = brackets $ hsep (punctuate comma (map ppBEncode l)) |
444 | PP.hsep (PP.punctuate PP.comma (map PP.pretty l)) <+> | 446 | ppBEncode (BDict d) = braces $ vcat (punctuate comma (map ppKV (M.toAscList d))) |
445 | PP.rbracket | 447 | where |
446 | pretty (BDict d) = | 448 | ppKV (k, v) = ppBS k <+> colon <+> ppBEncode v |
447 | PP.align $ PP.lbrace <+> | ||
448 | PP.vsep (PP.punctuate PP.comma (map ppKV (M.toAscList d))) </> | ||
449 | PP.rbrace | ||
450 | where | ||
451 | ppKV (k, v) = ppBS k <+> PP.colon <+> PP.pretty v | ||
452 | 449 | ||
453 | 450 | ||
454 | ------------------------------- other instances ------------------------------ | 451 | ------------------------------- other instances ------------------------------ |