From f55439cfcdef0f65b0be79f9efa17bf3fba5be9a Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Thu, 10 Jul 2008 15:53:00 +0000 Subject: Put brackets round operators in more places in the Hoogle output --- src/Haddock/Backends/Hoogle.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Haddock/Backends/Hoogle.hs b/src/Haddock/Backends/Hoogle.hs index f0eced51..33dd5da8 100644 --- a/src/Haddock/Backends/Hoogle.hs +++ b/src/Haddock/Backends/Hoogle.hs @@ -75,7 +75,12 @@ out = f . unwords . map (dropWhile isSpace) . lines . showSDocUnqual . ppr typeSig :: String -> [String] -> String -typeSig name flds = name ++ " :: " ++ concat (intersperse " -> " flds) +typeSig name flds = operator name ++ " :: " ++ concat (intersperse " -> " flds) + + +operator :: String -> String +operator (x:xs) | not (isAlphaNum x) && x `notElem` " ([{" = "(" ++ x:xs ++ ")" +operator x = x --------------------------------------------------------------------- @@ -117,7 +122,12 @@ ppData x = showData x{tcdCons=[],tcdDerivs=Nothing} : concatMap (ppCtor x . unL) (tcdCons x) where -- GHC gives out "data Bar =", we want to delete the equals - showData = reverse . dropWhile (`elem` " =") . reverse . out + -- also writes data : a b, when we want data (:) a b + showData x = unwords $ map f $ if last xs == "=" then init xs else xs + where + xs = words $ out x + nam = out $ tcdLName x + f x = if x == nam then operator nam else x ppCtor :: TyClDecl Name -> ConDecl Name -> [String] @@ -133,7 +143,7 @@ ppCtor dat con = ldoc (con_doc con) ++ f (con_details con) name = out $ unL $ con_name con resType = case con_res con of - ResTyH98 -> unwords $ out (tcdLName dat) : map out (tcdTyVars dat) + ResTyH98 -> unwords $ operator (out (tcdLName dat)) : map out (tcdTyVars dat) ResTyGADT x -> out $ unL x -- cgit v1.2.3