Add Set rules to PrettyShow.

As Neil pointed out, I'd already added some rules to PrettyShow to handle the
Maps in CompState; this does the same for the Sets, which means it's pshow-able
again.
This commit is contained in:
Adam Sampson 2007-08-22 23:06:50 +00:00
parent 36262fc55e
commit 9efa008443
3 changed files with 12 additions and 1 deletions

View File

@ -44,6 +44,11 @@ data CompFrontend = FrontendOccam | FrontendRain
-- | State necessary for compilation. -- | State necessary for compilation.
data CompState = CompState { data CompState = CompState {
-- This structure needs to be printable with pshow.
-- There are explicit rules for the Maps and Sets used here
-- in PrettyShow.hs; if you add any new ones here then remember
-- to add matching rules there.
-- Set by Main (from command-line options) -- Set by Main (from command-line options)
csMode :: CompMode, csMode :: CompMode,
csBackend :: CompBackend, csBackend :: CompBackend,

View File

@ -89,7 +89,7 @@ debugAST p
veryDebug $ "}}}" veryDebug $ "}}}"
veryDebug $ "{{{ State" veryDebug $ "{{{ State"
ps <- get ps <- get
veryDebug $ show ps veryDebug $ pshow ps
veryDebug $ "}}}" veryDebug $ "}}}"
-- | Number lines in a piece of text. -- | Number lines in a piece of text.

View File

@ -24,6 +24,7 @@ module PrettyShow (pshow) where
import Data.Generics import Data.Generics
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Set as Set
import Text.PrettyPrint.HughesPJ import Text.PrettyPrint.HughesPJ
import qualified AST as A import qualified AST as A
@ -66,6 +67,9 @@ doMap :: (Data a, Data b) => Map.Map a b -> Doc
doMap map = braces $ sep $ punctuate (text ",") [doAny k <+> text ":" <+> doAny v doMap map = braces $ sep $ punctuate (text ",") [doAny k <+> text ":" <+> doAny v
| (k, v) <- Map.toAscList map] | (k, v) <- Map.toAscList map]
doSet :: Data a => Set.Set a -> Doc
doSet set = brackets $ sep $ punctuate (text ",") (map doAny $ Set.toList set)
foldPatternList :: Pattern -> [Pattern] foldPatternList :: Pattern -> [Pattern]
foldPatternList (Match con patList) foldPatternList (Match con patList)
= if (showConstr con == "(:)") = if (showConstr con == "(:)")
@ -123,6 +127,8 @@ doAny = doGeneral `ext1Q` doList `extQ` doString `extQ` doMeta `extQ` doPattern
`extQ` (doMap :: Map.Map String A.NameDef -> Doc) `extQ` (doMap :: Map.Map String A.NameDef -> Doc)
`extQ` (doMap :: Map.Map String [A.Type] -> Doc) `extQ` (doMap :: Map.Map String [A.Type] -> Doc)
`extQ` (doMap :: Map.Map String [A.Actual] -> Doc) `extQ` (doMap :: Map.Map String [A.Actual] -> Doc)
`extQ` (doSet :: Set.Set String -> Doc)
`extQ` (doSet :: Set.Set A.Name -> Doc)
-- | Convert an arbitrary data structure to a string in a reasonably pretty way. -- | Convert an arbitrary data structure to a string in a reasonably pretty way.
-- This is currently rather slow. -- This is currently rather slow.