Improve depth-cutoff for printing HsSyn in error messages
[ghc-hetmet.git] / compiler / utils / Outputable.lhs
index db744b1..4f8d320 100644 (file)
@@ -14,7 +14,8 @@ module Outputable (
        BindingSite(..),
 
        PprStyle, CodeStyle(..), PrintUnqualified, alwaysQualify,
-       getPprStyle, withPprStyle, withPprStyleDoc, pprDeeper, pprSetDepth,
+       getPprStyle, withPprStyle, withPprStyleDoc, 
+       pprDeeper, pprDeeperList, pprSetDepth,
        codeStyle, userStyle, debugStyle, dumpStyle, asmStyle,
        ifPprDebug, qualName, qualModule,
        mkErrStyle, defaultErrStyle, defaultDumpStyle, defaultUserStyle,
@@ -25,7 +26,7 @@ module Outputable (
        empty, nest,
        text, char, ftext, ptext,
        int, integer, float, double, rational,
-       parens, brackets, braces, quotes, doubleQuotes, angleBrackets,
+       parens, cparen, brackets, braces, quotes, doubleQuotes, angleBrackets,
        semi, comma, colon, dcolon, space, equals, dot, arrow,
        lparen, rparen, lbrack, rbrack, lbrace, rbrace, underscore,
        (<>), (<+>), hcat, hsep, 
@@ -188,6 +189,19 @@ pprDeeper d (PprUser q (PartWay 0)) = Pretty.text "..."
 pprDeeper d (PprUser q (PartWay n)) = d (PprUser q (PartWay (n-1)))
 pprDeeper d other_sty              = d other_sty
 
+pprDeeperList :: ([SDoc] -> SDoc) -> [SDoc] -> SDoc
+-- Truncate a list that list that is longer than the current depth
+pprDeeperList f ds (PprUser q (PartWay n))
+  | n==0      = Pretty.text "..."
+  | otherwise = f (go 0 ds) (PprUser q (PartWay (n-1)))
+  where
+    go i [] = []
+    go i (d:ds) | i >= n    = [text "...."]
+               | otherwise = d : go (i+1) ds
+
+pprDeeperList f ds other_sty
+  = f ds other_sty
+
 pprSetDepth :: Int -> SDoc -> SDoc
 pprSetDepth n d (PprUser q _) = d (PprUser q (PartWay n))
 pprSetDepth n d other_sty     = d other_sty
@@ -311,6 +325,8 @@ brackets d sty     = Pretty.brackets (d sty)
 doubleQuotes d sty = Pretty.doubleQuotes (d sty)
 angleBrackets d    = char '<' <> d <> char '>'
 
+cparen b d sty       = Pretty.cparen b (d sty)
+
 -- quotes encloses something in single quotes...
 -- but it omits them if the thing ends in a single quote
 -- so that we don't get `foo''.  Instead we just have foo'.