packages feed

mainland-pretty 0.1.1.1 → 0.1.2.0

raw patch · 3 files changed

+52/−42 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Text.PrettyPrint.Mainland: instance [overlap ok] Monoid Doc
- Text.PrettyPrint.Mainland: (<>) :: Doc -> Doc -> Doc
+ Text.PrettyPrint.Mainland: (<>) :: Monoid m => m -> m -> m

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2006-2010+Copyright (c) 2006-2012         The President and Fellows of Harvard College.  Redistribution and use in source and binary forms, with or without
Text/PrettyPrint/Mainland.hs view
@@ -1,10 +1,12 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE UndecidableInstances #-} --- Copyright (c) 2006-2010+-- Copyright (c) 2006-2012 --         The President and Fellows of Harvard College. -- -- Redistribution and use in source and binary forms, with or without@@ -34,7 +36,7 @@ -------------------------------------------------------------------------------- -- | -- Module      :  Text.PrettyPrint.Mainland--- Copyright   :  (c) Harvard University 2006-2010+-- Copyright   :  (c) Harvard University 2006-2012 -- License     :  BSD-style -- Maintainer  :  mainland@eecs.harvard.edu --@@ -97,20 +99,20 @@   ) where  import Data.Int-import qualified Data.Map as Map-import qualified Data.Set as Set-import Data.Word- import Data.Loc (L(..),                  Loc(..),                  Located(..),                  Pos(..),                  posFile,                  posLine)+import qualified Data.Map as Map+import Data.Monoid+import qualified Data.Set as Set import Data.Symbol+import Data.Word  infixr 5 </>, <+/>, <//>-infixr 6 <>, <+>+infixr 6 <+>  data Doc = Empty                -- ^ The empty document          | Char Char            -- ^ A single character@@ -189,9 +191,6 @@ flatten (Column f)   = Column (flatten . f) flatten (Nesting f)  = Nesting (flatten . f) -(<>) :: Doc -> Doc -> Doc-x <> y = x `Cat` y- (<+>) :: Doc -> Doc -> Doc x <+> y = x <> space <> y @@ -438,18 +437,20 @@ renderCompact :: Doc -> RDoc renderCompact doc = scan 0 [doc]   where-    scan _ []     = REmpty-    scan k (d:ds) = case d of-                      Empty     -> scan k ds-                      Char c    -> let k' = k+1 in k' `seq` RChar c (scan k' ds)-                      Text l s  -> let k' = k+l in k' `seq` RText l s (scan k' ds)-                      Line      -> RLine 0 (scan 0 ds)-                      Nest _ x  -> scan k (x:ds)-                      SrcLoc _  -> scan k ds-                      Cat x y   -> scan k (x:y:ds)-                      Alt x _   -> scan k (x:ds)-                      Column f  -> scan k (f k:ds)-                      Nesting f -> scan k (f 0:ds)+    scan :: Int -> [Doc] -> RDoc+    scan !_ []     = REmpty+    scan !k (d:ds) =+        case d of+          Empty     -> scan k ds+          Char c    -> RChar c (scan (k+1) ds)+          Text l s  -> RText l s (scan (k+l) ds)+          Line      -> RLine 0 (scan 0 ds)+          Nest _ x  -> scan k (x:ds)+          SrcLoc _  -> scan k ds+          Cat x y   -> scan k (x:y:ds)+          Alt x _   -> scan k (x:ds)+          Column f  -> scan k (f k:ds)+          Nesting f -> scan k (f 0:ds)  -- | Display a rendered document. displayS :: RDoc -> ShowS@@ -530,7 +531,7 @@           | Cons !Int Doc Docs -- ^ Indentation, document and tail  best :: Int -> Int -> Doc -> RDoc-best w k x = be Nothing Nothing k id (Cons 0 x Nil)+best !w k x = be Nothing Nothing k id (Cons 0 x Nil)   where     be :: Maybe Pos -- ^ Previous source position        -> Maybe Pos -- ^ Current source position@@ -538,18 +539,15 @@        -> RDocS        -> Docs        -> RDoc-    be  _ _  _  f Nil           = f REmpty-    be  p p' k  f (Cons i d ds) =+    be  _ _  !_  f Nil           = f REmpty+    be  p p' !k  f (Cons i d ds) =         case d of           Empty      -> be p p' k f ds-          Char c     -> let k' = k + 1 in-                        k' `seq` be p p' k' (f . RChar c) ds-          Text l s   -> let k' = k + l in-                        k' `seq` be p p' k' (f . RText l s) ds+          Char c     -> be p p' (k+1) (f . RChar c) ds+          Text l s   -> be p p' (k+l) (f . RText l s) ds           Line       -> (f . pragma . RLine i) (be p'' Nothing i id ds)           x `Cat` y  -> be p p' k f (Cons i x (Cons i y ds))-          Nest j x   -> let j' = i + j in-                        j' `seq` be p p' k f (Cons j' x ds)+          Nest j x   -> be p p' k f (Cons (i+j) x ds)           x `Alt` y  -> better k f (be p p' k id (Cons i x ds))                                    (be p p' k id (Cons i y ds))           SrcLoc loc -> be p (merge p' loc) k f ds@@ -559,16 +557,28 @@         (p'', pragma) = lineloc p p'      better :: Int -> RDocS -> RDoc -> RDoc -> RDoc-    better k f x y | fits (w - k) x = f x-                   | otherwise      = f y+    better !k f x y | fits (w - k) x = f x+                    | otherwise      = f y      fits :: Int -> RDoc -> Bool-    fits  w  _        | w < 0 = False-    fits  _  REmpty           = True-    fits  w  (RChar _ x)      = fits (w - 1) x-    fits  w  (RText l _ x)    = fits (w - l) x-    fits  w  (RPos _ x)       = fits w x-    fits  _  (RLine _ _)      = True+    fits  !w  _        | w < 0 = False+    fits  !_  REmpty           = True+    fits  !w  (RChar _ x)      = fits (w - 1) x+    fits  !w  (RText l _ x)    = fits (w - l) x+    fits  !w  (RPos _ x)       = fits w x+    fits  !_  (RLine _ _)      = True++#if MIN_VERSION_base(4,5,0)+#else+infixr 6 <>++(<>) :: Doc -> Doc -> Doc+x <> y = x `Cat` y+#endif++instance Monoid Doc where+    mempty  = empty+    mappend = Cat  class Pretty a where     ppr     :: a -> Doc
mainland-pretty.cabal view
@@ -1,9 +1,9 @@ name:           mainland-pretty-version:        0.1.1.1+version:        0.1.2.0 cabal-version:  >= 1.6 license:        BSD3 license-file:   LICENSE-copyright:      (c) 2006-2010 Harvard University+copyright:      (c) 2006-2012 Harvard University author:         Geoffrey Mainland <mainland@eecs.harvard.edu> maintainer:     mainland@eecs.harvard.edu stability:      alpha