wl-pprint-text 1.1.0.3 → 1.1.0.4
raw patch · 3 files changed
+62/−54 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- Text/PrettyPrint/Leijen/Text.hs +47/−41
- Text/PrettyPrint/Leijen/Text/Monadic.hs +12/−10
- wl-pprint-text.cabal +3/−3
Text/PrettyPrint/Leijen/Text.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Text.PrettyPrint.Leijen.Text@@ -117,17 +118,22 @@ ) where -import Data.String (IsString(fromString))-import System.IO (Handle,hPutStr,hPutChar,stdout)+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 710+import Prelude hiding ((<$>))+#endif -import qualified Data.Text.Lazy as T-import Data.Text.Lazy(Text)-import qualified Data.Text.Lazy.IO as T+import Data.String (IsString (..))+import System.IO (Handle, hPutChar, stdout)++import Data.Int (Int64)+import Data.Monoid (Monoid (..))+import Data.Text.Lazy (Text)+import qualified Data.Text.Lazy as T+import Data.Text.Lazy.Builder (Builder) import qualified Data.Text.Lazy.Builder as B-import Data.Text.Lazy.Builder(Builder)-import Data.Int(Int64)-import Data.Monoid(Monoid(mempty,mappend))+import qualified Data.Text.Lazy.IO as T + infixr 5 </>,<//>,<$>,<$$> infixr 6 <>,<+>,<++> @@ -186,11 +192,11 @@ -- ,3000] -- @ encloseSep :: Doc -> Doc -> Doc -> [Doc] -> Doc-encloseSep left right sep ds+encloseSep left right sp ds = case ds of [] -> left <> right [d] -> left <> d <> right- _ -> align (cat (zipWith (<>) (left : repeat sep) ds) <> right)+ _ -> align (cat (zipWith (<>) (left : repeat sp) ds) <> right) ----------------------------------------------------------- -- punctuate p [d1,d2,...,dn] => [d1 <> p,d2 <> p, ... ,dn]@@ -221,8 +227,8 @@ -- (If you want put the commas in front of their elements instead of -- at the end, you should use 'tupled' or, in general, 'encloseSep'.) punctuate :: Doc -> [Doc] -> [Doc]-punctuate p [] = []-punctuate p [d] = [d]+punctuate _ [] = []+punctuate _ [d] = [d] punctuate p (d:ds) = (d <> p) : punctuate p ds @@ -315,7 +321,7 @@ vcat = fold (<$$>) fold :: (Doc -> Doc -> Doc) -> [Doc] -> Doc-fold f [] = empty+fold _ [] = empty fold f ds = foldr1 f ds -- | The document @(x \<\> y)@ concatenates document @x@ and document@@ -859,13 +865,13 @@ group x = Union (flatten x) x flatten :: Doc -> Doc-flatten (Cat x y) = Cat (flatten x) (flatten y)-flatten (Nest i x) = Nest i (flatten x)-flatten (Line break) = if break then Empty else Text 1 (B.singleton ' ')-flatten (Union x y) = flatten x-flatten (Column f) = Column (flatten . f)-flatten (Nesting f) = Nesting (flatten . f)-flatten other = other --Empty,Char,Text+flatten (Cat x y) = Cat (flatten x) (flatten y)+flatten (Nest i x) = Nest i (flatten x)+flatten (Line brk) = if brk then Empty else Text 1 (B.singleton ' ')+flatten (Union x _) = flatten x+flatten (Column f) = Column (flatten . f)+flatten (Nesting f) = Nesting (flatten . f)+flatten other = other --Empty,Char,Text ----------------------------------------------------------- -- Renderers@@ -888,8 +894,8 @@ -- is lower or higher, the ribbon width will be 0 or @width@ -- respectively. renderPretty :: Float -> Int -> Doc -> SimpleDoc-renderPretty rfrac w x- = best 0 0 (Cons 0 x Nil)+renderPretty rfrac w doc+ = best 0 0 (Cons 0 doc Nil) where -- r :: the ribbon width in characters r = max 0 (min w64 (round (fromIntegral w * rfrac)))@@ -899,7 +905,7 @@ -- best :: n = indentation of current line -- k = current column -- (ie. (k >= n) && (k - n == count of inserted characters)- best n k Nil = SEmpty+ best _ _ Nil = SEmpty best n k (Cons i d ds) = case d of Empty -> best n k ds@@ -919,17 +925,17 @@ -- x and y, the (simple) documents to chose from. -- precondition: first lines of x are longer than the first lines of y. nicest n k x y- | fits width x = x+ | fits wth x = x | otherwise = y where- width = min (w64 - k) (r - k + n)+ wth = min (w64 - k) (r - k + n) fits :: Int64 -> SimpleDoc -> Bool-fits w x | w < 0 = False-fits w SEmpty = True-fits w (SChar c x) = fits (w - 1) x-fits w (SText l s x) = fits (w - l) x-fits w (SLine i x) = True+fits w _ | w < 0 = False+fits _ SEmpty = True+fits w (SChar _ x) = fits (w - 1) x+fits w (SText l _ x) = fits (w - l) x+fits _ SLine{} = True ----------------------------------------------------------- -- renderCompact: renders documents without indentation@@ -942,10 +948,10 @@ -- characters than a pretty printed version and can be used for -- output that is read by other programs. renderCompact :: Doc -> SimpleDoc-renderCompact x- = scan 0 [x]+renderCompact dc+ = scan 0 [dc] where- scan k [] = SEmpty+ scan _ [] = SEmpty scan k (d:ds) = case d of Empty -> scan k ds@@ -953,8 +959,8 @@ Text l s -> let k' = k+l in seq k' (SText l s (scan k' ds)) Line _ -> SLine 0 (scan 0 ds) Cat x y -> scan k (x:y:ds)- Nest j x -> scan k (x:ds)- Union x y -> scan k (y:ds)+ Nest _ x -> scan k (x:ds)+ Union _ y -> scan k (y:ds) Column f -> scan k (f k:ds) Nesting f -> scan k (f 0:ds) Spaces _ -> scan k ds@@ -962,10 +968,10 @@ -- | @(renderOneLine x)@ renders document @x@ without adding any -- indentation or newlines. renderOneLine :: Doc -> SimpleDoc-renderOneLine x- = scan 0 [x]+renderOneLine dc+ = scan 0 [dc] where- scan k [] = SEmpty+ scan _ [] = SEmpty scan k (d:ds) = case d of Empty -> scan k ds@@ -974,8 +980,8 @@ Line False -> let k' = k+1 in seq k' (SChar ' ' (scan k' ds)) Line _ -> scan k ds Cat x y -> scan k (x:y:ds)- Nest j x -> scan k (x:ds)- Union x y -> scan k (y:ds)+ Nest _ x -> scan k (x:ds)+ Union _ y -> scan k (y:ds) Column f -> scan k (f k:ds) Nesting f -> scan k (f 0:ds) Spaces _ -> scan k ds@@ -1016,7 +1022,7 @@ where display SEmpty = return () display (SChar c x) = hPutChar handle c >> display x- display (SText l s x) = T.hPutStr handle (B.toLazyText s) >> display x+ display (SText _ s x) = T.hPutStr handle (B.toLazyText s) >> display x display (SLine i x) = T.hPutStr handle newLine >> display x where newLine = B.toLazyText $ '\n' `consB` indentation i
Text/PrettyPrint/Leijen/Text/Monadic.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE CPP, FlexibleInstances #-} ----------------------------------------------------------------------------- -- |@@ -69,16 +69,19 @@ ) where +#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 710+import Prelude hiding ((<$>))+#endif++import Text.PrettyPrint.Leijen.Text (Doc, Pretty (..), SimpleDoc (..),+ displayB, displayIO, displayT,+ hPutDoc, putDoc, renderCompact,+ renderOneLine, renderPretty) import qualified Text.PrettyPrint.Leijen.Text as PP-import Text.PrettyPrint.Leijen.Text( Doc, SimpleDoc(..)- , renderPretty, renderCompact, renderOneLine- , displayB, displayT, displayIO- , putDoc, hPutDoc, Pretty(..)) -import Data.String (IsString(fromString))-import Control.Monad(liftM, liftM2, liftM3, liftM4)-import Data.Text.Lazy(Text)-import Data.Int(Int64)+import Control.Monad (liftM, liftM2, liftM3, liftM4)+import Data.String (IsString (..))+import Data.Text.Lazy (Text) infixr 5 </>,<//>,<$>,<$$> infixr 6 <>,<+>,<++>@@ -629,4 +632,3 @@ -- without any changes. group :: (Monad m) => m Doc -> m Doc group = liftM PP.group-
wl-pprint-text.cabal view
@@ -1,5 +1,5 @@ Name: wl-pprint-text-Version: 1.1.0.3+Version: 1.1.0.4 Synopsis: A Wadler/Leijen Pretty Printer for Text values Description: A clone of wl-pprint for use with the text library. License: BSD3@@ -12,8 +12,8 @@ Cabal-version: >=1.6 Source-Repository head- type: darcs- location: http://hub.darcs.net/ivanm/wl-pprint-text+ type: git+ location: git://github.com/ivan-m/wl-pprint-text.git Library Exposed-modules: Text.PrettyPrint.Leijen.Text,