summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsimonpj <unknown>2005-07-11 09:48:19 +0000
committersimonpj <unknown>2005-07-11 09:48:19 +0000
commit0aaa6c3bb4df2afdf2b99251966df7777e7396b8 (patch)
treeb9e8cdd8c75b9af9a83531febaef61139e88db8a
parent90a2c9cb2e8fe1b4e156a4c78179ea9eb1adaaf2 (diff)
downloadhaskell-0aaa6c3bb4df2afdf2b99251966df7777e7396b8.tar.gz
[project @ 2005-07-11 09:48:19 by simonpj]
Add speakN, and the ability to set printing depth
-rw-r--r--ghc/compiler/utils/Outputable.lhs20
1 files changed, 15 insertions, 5 deletions
diff --git a/ghc/compiler/utils/Outputable.lhs b/ghc/compiler/utils/Outputable.lhs
index f870b654c8..a12f46d1ae 100644
--- a/ghc/compiler/utils/Outputable.lhs
+++ b/ghc/compiler/utils/Outputable.lhs
@@ -14,7 +14,7 @@ module Outputable (
BindingSite(..),
PprStyle, CodeStyle(..), PrintUnqualified, alwaysQualify,
- getPprStyle, withPprStyle, withPprStyleDoc, pprDeeper,
+ getPprStyle, withPprStyle, withPprStyleDoc, pprDeeper, pprSetDepth,
codeStyle, userStyle, debugStyle, dumpStyle, asmStyle,
ifPprDebug, unqualStyle,
mkErrStyle, defaultErrStyle,
@@ -33,7 +33,7 @@ module Outputable (
sep, cat,
fsep, fcat,
hang, punctuate,
- speakNth, speakNTimes,
+ speakNth, speakNTimes, speakN,
printSDoc, printErrs, printDump,
printForC, printForAsm, printForUser,
@@ -156,6 +156,10 @@ pprDeeper d (PprUser unqual (PartWay 0)) = Pretty.text "..."
pprDeeper d (PprUser unqual (PartWay n)) = d (PprUser unqual (PartWay (n-1)))
pprDeeper d other_sty = d other_sty
+pprSetDepth :: Int -> SDoc -> SDoc
+pprSetDepth n d (PprUser unqual _) = d (PprUser unqual (PartWay n))
+pprSetDepth n d other_sty = d other_sty
+
getPprStyle :: (PprStyle -> SDoc) -> SDoc
getPprStyle df sty = df sty sty
\end{code}
@@ -455,7 +459,6 @@ pprQuotedList xs = hsep (punctuate comma (map (quotes . ppr) xs))
\begin{code}
speakNth :: Int -> SDoc
-
speakNth 1 = ptext SLIT("first")
speakNth 2 = ptext SLIT("second")
speakNth 3 = ptext SLIT("third")
@@ -471,9 +474,16 @@ speakNth n = hcat [ int n, text suffix ]
| otherwise = "th"
last_dig = n `rem` 10
-\end{code}
-\begin{code}
+speakN :: Int -> SDoc
+speakN 1 = ptext SLIT("one")
+speakN 2 = ptext SLIT("two")
+speakN 3 = ptext SLIT("three")
+speakN 4 = ptext SLIT("four")
+speakN 5 = ptext SLIT("five")
+speakN 6 = ptext SLIT("six")
+speakN n = int n
+
speakNTimes :: Int {- >=1 -} -> SDoc
speakNTimes t | t == 1 = ptext SLIT("once")
| t == 2 = ptext SLIT("twice")