on master help sign in
Refactor detection of things that do not require extra parentheses
0d4da7fmrkkrp
src/Ormolu/Printer/Meat/Common.hs+4−11
@@ -13,6 +13,7 @@ module Ormolu.Printer.Meat.Common
13 )
13 )
14where
14where
15
15
16+import Data.List (isPrefixOf)
16import GHC hiding (GhcPs, IE)
17import GHC hiding (GhcPs, IE)
17import Module (Module (..))
18import Module (Module (..))
18import Name (nameStableString)
19import Name (nameStableString)
@@ -68,7 +69,9 @@ p_rdrName l@(L spn _) = located l $ \x -> do
68 -- NOTE I'm not sure this "stable string" is stable enough, but
69 -- NOTE I'm not sure this "stable string" is stable enough, but
69 -- it looks like this is the most robust way to tell if we're
70 -- it looks like this is the most robust way to tell if we're
70 -- looking at exactly this piece of built-in syntax.
71 -- looking at exactly this piece of built-in syntax.
72+ ( atom name
71− (atom name, nameStableString name `elem` avoidParensStableNames)
73+ , "$ghc-prim$GHC.Tuple$" `isPrefixOf` nameStableString name
74+ )
72 if avoidParens
75 if avoidParens
73 then m
76 then m
74 else parensWrapper (backticksWrapper m)
77 else parensWrapper (backticksWrapper m)
@@ -83,13 +86,3 @@ p_ieWildcard :: IEWildcard -> R ()
83p_ieWildcard = \case
86p_ieWildcard = \case
84 NoIEWildcard -> return ()
87 NoIEWildcard -> return ()
85 IEWildcard n -> parens (atom n)
88 IEWildcard n -> parens (atom n)
86−
87−avoidParensStableNames :: [String]
88−avoidParensStableNames =
89− [ "$ghc-prim$GHC.Tuple$()"
90− , "$ghc-prim$GHC.Tuple$(,)"
91− , "$ghc-prim$GHC.Tuple$(,,)"
92− , "$ghc-prim$GHC.Tuple$(,,,)"
93− , "$ghc-prim$GHC.Tuple$(,,,,)"
94− , "$ghc-prim$GHC.Tuple$(,,,,,)"
95− ]