packages feed

wl-pprint-text 1.1.0.0 → 1.1.0.1

raw patch · 3 files changed

+101/−70 lines, 3 filesdep ~text

Dependency ranges changed: text

Files

Text/PrettyPrint/Leijen/Text.hs view
@@ -70,24 +70,24 @@     -- * Basic combinators    empty, char, text, (<>), nest, line, linebreak, group, softline,-   softbreak,+   softbreak, spacebreak,     -- * Alignment    ---   -- The combinators in this section can not be described by Wadler's-   -- original combinators. They align their output relative to the-   -- current output position - in contrast to @nest@ which always-   -- aligns to the current nesting level. This deprives these-   -- combinators from being \`optimal\'. In practice however they-   -- prove to be very useful. The combinators in this section should-   -- be used with care, since they are more expensive than the other-   -- combinators. For example, @align@ shouldn't be used to pretty-   -- print all top-level declarations of a language, but using @hang@-   -- for let expressions is fine.+   -- | The combinators in this section can not be described by Wadler's+   --   original combinators. They align their output relative to the+   --   current output position - in contrast to @nest@ which always+   --   aligns to the current nesting level. This deprives these+   --   combinators from being \`optimal\'. In practice however they+   --   prove to be very useful. The combinators in this section should+   --   be used with care, since they are more expensive than the other+   --   combinators. For example, @align@ shouldn't be used to pretty+   --   print all top-level declarations of a language, but using @hang@+   --   for let expressions is fine.    align, hang, indent, encloseSep, list, tupled, semiBraces,     -- * Operators-   (<+>), (<$>), (</>), (<$$>), (<//>),+   (<+>), (<++>), (<$>), (</>), (<$$>), (<//>),     -- * List combinators    hsep, vsep, fillSep, sep, hcat, vcat, fillCat, cat, punctuate,@@ -113,7 +113,7 @@     -- * Rendering    SimpleDoc(..), renderPretty, renderCompact, renderOneLine,-   displayT, displayIO, putDoc, hPutDoc+   displayB, displayT, displayIO, putDoc, hPutDoc     ) where @@ -129,7 +129,7 @@ import Data.Monoid(Monoid(mempty,mappend))  infixr 5 </>,<//>,<$>,<$$>-infixr 6 <>,<+>+infixr 6 <>,<+>,<++>   -----------------------------------------------------------@@ -172,13 +172,13 @@ --   > list xs = encloseSep lbracket rbracket comma xs --   > test = text "list" <+> (list (map int [10,200,3000])) -----   Which is layed out with a page width of 20 as:+--   Which is laid out with a page width of 20 as: -- --   @ --   list [10,200,3000] --   @ -----   But when the page width is 15, it is layed out as:+--   But when the page width is 15, it is laid out as: -- --   @ --   list [10@@ -203,13 +203,13 @@ --   > someText = map text ["words","in","a","tuple"] --   > test = parens (align (cat (punctuate comma someText))) -----   This is layed out on a page width of 20 as:+--   This is laid out on a page width of 20 as: -- --   @ --   (words,in,a,tuple) --   @ -----   But when the page width is 15, it is layed out as:+--   But when the page width is 15, it is laid out as: -- --   @ --   (words,@@ -240,7 +240,7 @@ sep = group . vsep  -- | The document @(fillSep xs)@ concatenates documents @xs@---   horizontally with @(\<+\>)@ as long as its fits the page, than+--   horizontally with @(\<+\>)@ as long as its fits the page, then --   inserts a @line@ and continues doing that for all documents in --   @xs@. --@@ -261,7 +261,7 @@ --   > --   > test = text "some" <+> vsep someText -----   This is layed out as:+--   This is laid out as: -- --   @ --   some text@@ -295,7 +295,7 @@ cat = group . vcat  -- | The document @(fillCat xs)@ concatenates documents @xs@---   horizontally with @(\<\>)@ as long as its fits the page, than+--   horizontally with @(\<\>)@ as long as its fits the page, then --   inserts a @linebreak@ and continues doing that for all documents --   in @xs@. --@@ -325,12 +325,20 @@ x <> y = x `beside` y  -- | The document @(x \<+\> y)@ concatenates document @x@ and @y@ with---   a @space@ in between.  (infixr 6)+--   a 'space' in between.  (infixr 6) (<+>) :: Doc -> Doc -> Doc Empty <+> y     = y x     <+> Empty = x x     <+> y     = x <> space <> y +-- | The document @(x \<++\> y)@ concatenates document @x@ and @y@ with+--   a 'spacebreak' in between.  (infixr 6)+(<++>) :: Doc -> Doc -> Doc+Empty <++> y     = y+x     <++> Empty = x+x     <++> y     = x <> spacebreak <> y++ -- | The document @(x \<\/\> y)@ concatenates document @x@ and @y@ --   with a 'softline' in between. This effectively puts @x@ and @y@ --   either next to each other (with a @space@ in between) or@@ -356,7 +364,7 @@ (<$>) = splitWithLine False  -- | The document @(x \<$$\> y)@ concatenates document @x@ and @y@---   with a @linebreak@ in between. (infixr 5)+--   with a 'linebreak' in between. (infixr 5) (<$$>) :: Doc -> Doc -> Doc (<$$>) = splitWithLine True @@ -379,6 +387,11 @@ softbreak :: Doc softbreak = group linebreak +-- | The document @spacebreak@ behaves like 'space' when rendered normally+-- but like 'empty' when using 'renderCompact' or 'renderOneLine'.+spacebreak :: Doc+spacebreak = Spaces 1+ -- | Document @(squotes x)@ encloses document @x@ with single quotes --   \"'\". squotes :: Doc -> Doc@@ -600,7 +613,7 @@ -----------------------------------------------------------  -- | The document @(fillBreak i x)@ first renders document @x@. It---   than appends @space@s until the width is equal to @i@. If the+--   then appends @space@s until the width is equal to @i@. If the --   width of @x@ is already larger than @i@, the nesting level is --   increased by @i@ and a @line@ is appended. When we redefine --   @ptype@ in the previous example to use @fillBreak@, we get a@@ -625,7 +638,7 @@                         )  --- | The document @(fill i x)@ renders document @x@. It than appends+-- | The document @(fill i x)@ renders document @x@. It then appends --   @space@s until the width is equal to @i@. If the width of @x@ is --   already larger, nothing is appended. This combinator is quite --   useful in practice to output a list of bindings. The following@@ -640,7 +653,7 @@ --   > --   > test = text "let" <+> align (vcat (map ptype types)) -----   Which is layed out as:+--   Which is laid out as: -- --   @ --   let empty  :: Doc@@ -712,7 +725,7 @@ -- --   > test = text "hi" <+> (text "nice" $$ text "world") -----   which will be layed out as:+--   which will be laid out as: -- --   @ --   hi nice@@ -749,6 +762,7 @@          | Union Doc Doc         -- invariant: first lines of first doc longer than the first lines of the second doc          | Column  (Int64 -> Doc)          | Nesting (Int64 -> Doc)+         | Spaces !Int64  instance IsString Doc where   fromString = string . T.pack@@ -794,7 +808,8 @@  -- | The @line@ document advances to the next line and indents to the --   current nesting level. Document @line@ behaves like @(text \"---   \")@ if the line break is undone by 'group'.+--   \")@ if the line break is undone by 'group' or if rendered with+--   'renderOneLine'. line :: Doc line = Line False @@ -897,6 +912,7 @@                                     (best n k $ Cons i y ds)             Column f  -> best n k (Cons i (f k) ds)             Nesting f -> best n k (Cons i (f i) ds)+            Spaces l  -> let k' = k+l in seq k' $ SText l (spaces l) (best n k' ds)        --nicest :: r = ribbon width, w = page width,       --          n = indentation of current line, k = current column@@ -941,6 +957,7 @@             Union x y -> scan k (y:ds)             Column f  -> scan k (f k:ds)             Nesting f -> scan k (f 0:ds)+            Spaces _  -> scan k ds  -- | @(renderOneLine x)@ renders document @x@ without adding any --   indentation or newlines.@@ -951,15 +968,17 @@       scan k [] = SEmpty       scan k (d:ds)         = case d of-            Empty     -> scan k ds-            Char c    -> let k' = k+1 in seq k' (SChar c (scan k' ds))-            Text l s  -> let k' = k+l in seq k' (SText l s (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)-            Column f  -> scan k (f k:ds)-            Nesting f -> scan k (f 0:ds)+            Empty      -> scan k ds+            Char c     -> let k' = k+1 in seq k' (SChar c (scan k' ds))+            Text l s   -> let k' = k+l in seq k' (SText l s (scan k' ds))+            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)+            Column f   -> scan k (f k:ds)+            Nesting f  -> scan k (f 0:ds)+            Spaces _   -> scan k ds  ----------------------------------------------------------- -- Displayers:  displayS and displayIO@@ -1050,7 +1069,7 @@   | otherwise = B.fromLazyText $ T.replicate n (T.singleton ' ')  spaced   :: Int -> Doc-spaced l = Text l' $ spaces l'+spaced l = Spaces l'   where     l' = fromIntegral l 
Text/PrettyPrint/Leijen/Text/Monadic.hs view
@@ -22,24 +22,24 @@     -- * Basic combinators    empty, char, text, (<>), nest, line, linebreak, group, softline,-   softbreak,+   softbreak, spacebreak,     -- * Alignment    ---   -- The combinators in this section can not be described by Wadler's-   -- original combinators. They align their output relative to the-   -- current output position - in contrast to @nest@ which always-   -- aligns to the current nesting level. This deprives these-   -- combinators from being \`optimal\'. In practice however they-   -- prove to be very useful. The combinators in this section should-   -- be used with care, since they are more expensive than the other-   -- combinators. For example, @align@ shouldn't be used to pretty-   -- print all top-level declarations of a language, but using @hang@-   -- for let expressions is fine.+   -- | The combinators in this section can not be described by Wadler's+   --   original combinators. They align their output relative to the+   --   current output position - in contrast to @nest@ which always+   --   aligns to the current nesting level. This deprives these+   --   combinators from being \`optimal\'. In practice however they+   --   prove to be very useful. The combinators in this section should+   --   be used with care, since they are more expensive than the other+   --   combinators. For example, @align@ shouldn't be used to pretty+   --   print all top-level declarations of a language, but using @hang@+   --   for let expressions is fine.    align, hang, indent, encloseSep, list, tupled, semiBraces,     -- * Operators-   (<+>), (<$>), (</>), (<$$>), (<//>),+   (<+>), (<++>), (<$>), (</>), (<$$>), (<//>),     -- * List combinators    hsep, vsep, fillSep, sep, hcat, vcat, fillCat, cat, punctuate,@@ -65,14 +65,15 @@     -- * Rendering    SimpleDoc(..), renderPretty, renderCompact, renderOneLine,-   displayT, displayIO, putDoc, hPutDoc+   displayB, displayT, displayIO, putDoc, hPutDoc     ) where  import qualified Text.PrettyPrint.Leijen.Text as PP import Text.PrettyPrint.Leijen.Text( Doc, SimpleDoc(..)                                    , renderPretty, renderCompact, renderOneLine-                                   , displayT, displayIO, putDoc, hPutDoc, Pretty(..))+                                   , displayB, displayT, displayIO+                                   , putDoc, hPutDoc, Pretty(..))  import Data.String (IsString(fromString)) import Control.Monad(liftM, liftM2, liftM3, liftM4)@@ -80,7 +81,7 @@ import Data.Int(Int64)  infixr 5 </>,<//>,<$>,<$$>-infixr 6 <>,<+>+infixr 6 <>,<+>,<++>  instance Monad m => IsString (m Doc) where     fromString = string . fromString@@ -121,13 +122,13 @@ --   > list xs = encloseSep lbracket rbracket comma xs --   > test = text "list" <+> (list (map int [10,200,3000])) -----   Which is layed out with a page width of 20 as:+--   Which is laid out with a page width of 20 as: -- --   @ --   list [10,200,3000] --   @ -----   But when the page width is 15, it is layed out as:+--   But when the page width is 15, it is laid out as: -- --   @ --   list [10@@ -143,13 +144,13 @@ --   > someText = map text ["words","in","a","tuple"] --   > test = parens (align (cat (punctuate comma someText))) -----   This is layed out on a page width of 20 as:+--   This is laid out on a page width of 20 as: -- --   @ --   (words,in,a,tuple) --   @ -----   But when the page width is 15, it is layed out as:+--   But when the page width is 15, it is laid out as: -- --   @ --   (words,@@ -172,7 +173,7 @@ sep = liftM PP.sep  -- | The document @(fillSep xs)@ concatenates documents @xs@---   horizontally with @(\<+\>)@ as long as its fits the page, than+--   horizontally with @(\<+\>)@ as long as its fits the page, then --   inserts a @line@ and continues doing that for all documents in --   @xs@. --@@ -193,7 +194,7 @@ --   > --   > test = text "some" <+> vsep someText -----   This is layed out as:+--   This is laid out as: -- --   @ --   some text@@ -227,7 +228,7 @@ cat = liftM PP.cat  -- | The document @(fillCat xs)@ concatenates documents @xs@---   horizontally with @(\<\>)@ as long as its fits the page, than+--   horizontally with @(\<\>)@ as long as its fits the page, then --   inserts a @linebreak@ and continues doing that for all documents --   in @xs@. --@@ -253,10 +254,15 @@ (<>) = liftM2 (PP.<>)  -- | The document @(x \<+\> y)@ concatenates document @x@ and @y@ with---   a @space@ in between.  (infixr 6)+--   a 'space' in between.  (infixr 6) (<+>) :: (Monad m) => m Doc -> m Doc -> m Doc (<+>) = liftM2 (PP.<+>) +-- | The document @(x \<++\> y)@ concatenates document @x@ and @y@ with+--   a 'spacebreak' in between.  (infixr 6)+(<++>) :: (Monad m) => m Doc -> m Doc -> m Doc+(<++>) = liftM2 (PP.<++>)+ -- | The document @(x \<\/\> y)@ concatenates document @x@ and @y@ --   with a 'softline' in between. This effectively puts @x@ and @y@ --   either next to each other (with a @space@ in between) or@@ -277,7 +283,7 @@ (<$>) = liftM2 (PP.<$>)  -- | The document @(x \<$$\> y)@ concatenates document @x@ and @y@---   with a @linebreak@ in between. (infixr 5)+--   with a 'linebreak' in between. (infixr 5) (<$$>) :: (Monad m) => m Doc -> m Doc -> m Doc (<$$>) = liftM2 (PP.<$$>) @@ -291,6 +297,11 @@ softbreak :: (Monad m) => m Doc softbreak = return PP.softbreak +-- | The document @spacebreak@ behaves like 'space' when rendered normally+-- but like 'empty' when using 'renderCompact' or 'renderOneLine'.+spacebreak :: (Monad m) => m Doc+spacebreak = return PP.spacebreak+ -- | Document @(squotes x)@ encloses document @x@ with single quotes --   \"'\". squotes :: (Monad m) => m Doc -> m Doc@@ -446,7 +457,7 @@ prettyM :: (Pretty a, Monad m) => a -> m Doc prettyM = return . pretty --- | The document @(fill i x)@ renders document @x@. It than appends+-- | The document @(fill i x)@ renders document @x@. It then appends --   @space@s until the width is equal to @i@. If the width of @x@ is --   already larger, nothing is appended. This combinator is quite --   useful in practice to output a list of bindings. The following@@ -461,7 +472,7 @@ --   > --   > test = text "let" <+> align (vcat (map ptype types)) -----   Which is layed out as:+--   Which is laid out as: -- --   @ --   let empty  :: Doc@@ -476,7 +487,7 @@ width = liftM2 PP.width  -- | The document @(fillBreak i x)@ first renders document @x@. It---   than appends @space@s until the width is equal to @i@. If the+--   then appends @space@s until the width is equal to @i@. If the --   width of @x@ is already larger than @i@, the nesting level is --   increased by @i@ and a @line@ is appended. When we redefine --   @ptype@ in the previous example to use @fillBreak@, we get a@@ -545,7 +556,7 @@ -- --   > test = text "hi" <+> (text "nice" $$ text "world") -----   which will be layed out as:+--   which will be laid out as: -- --   @ --   hi nice@@ -575,7 +586,8 @@  -- | The @line@ document advances to the next line and indents to the --   current nesting level. Document @line@ behaves like @(text \"---   \")@ if the line break is undone by 'group'.+--   \")@ if the line break is undone by 'group' or if rendered with+--   'renderOneLine'. line :: (Monad m) => m Doc line = return PP.line 
wl-pprint-text.cabal view
@@ -1,5 +1,5 @@ Name:                wl-pprint-text-Version:             1.1.0.0+Version:             1.1.0.1 Synopsis:            A Wadler/Leijen Pretty Printer for Text values Description:         A clone of wl-pprint for use with the text library. License:             BSD3@@ -13,10 +13,10 @@  Source-Repository head     type: darcs-    location: http://code.haskell.org/~ivanm/wl-pprint-text+    location: http://hub.darcs.net/ivanm/wl-pprint-text  Library   Exposed-modules:     Text.PrettyPrint.Leijen.Text,                        Text.PrettyPrint.Leijen.Text.Monadic   Build-depends:       base < 5,-                       text >= 0.11.0.0 && < 0.12.0.0+                       text >= 0.11.0.0 && < 1.1.0.0