-instance (NamedThing name, Outputable name) => Outputable (IE name) where
- ppr sty (IEVar var) = ppr sty var
- ppr sty (IEThingAbs thing) = ppr sty thing
- ppr sty (IEThingAll thing)
- = hcat [ppr sty thing, text "(..)"]
- ppr sty (IEThingWith thing withs)
- = (<>) (ppr sty thing)
- (parens (fsep (punctuate comma (map (ppr sty) withs))))
- ppr sty (IEModuleContents mod)
- = (<>) (ptext SLIT("module ")) (ptext mod)
+pprHsVar :: Outputable name => name -> SDoc
+pprHsVar v | isOperator ppr_v = parens ppr_v
+ | otherwise = ppr_v
+ where
+ ppr_v = ppr v
+
+isOperator :: SDoc -> Bool
+isOperator ppr_v
+ = case showSDocUnqual ppr_v of
+ ('(':s) -> False -- (), (,) etc
+ ('[':s) -> False -- []
+ ('$':c:s) -> not (isAlpha c) -- Don't treat $d as an operator
+ (':':c:s) -> not (isAlpha c) -- Don't treat :T as an operator
+ ('_':s) -> False -- Not an operator
+ (c:s) -> not (isAlpha c) -- Starts with non-alpha
+ other -> False
+ -- We use (showSDoc (ppr v)), rather than isSymOcc (getOccName v) simply so
+ -- that we don't need NamedThing in the context of all these functions.
+ -- Gruesome, but simple.