on master help sign in
Refactor detection of things that do not require extra parentheses
commit0d4da7f4eb2503907508e007d7a81f65ffb409e8 authormrkkrp <mark.karpov@tweag.io> dateWed 12 Jun 2019, 20:10 (7 years ago) parent057a3cf
1 file changed+4−11
src/Ormolu/Printer/Meat/Common.hs+4−11
src/Ormolu/Printer/Meat/Common.hs+4−11
@@ -13,6 +13,7 @@ module Ormolu.Printer.Meat.Common
1313 )
1414where
1515
16+import Data.List (isPrefixOf)
1617import GHC hiding (GhcPs, IE)
1718import Module (Module (..))
1819import Name (nameStableString)
@@ -68,7 +69,9 @@ p_rdrName l@(L spn _) = located l $ \x -> do
6869 -- NOTE I'm not sure this "stable string" is stable enough, but
6970 -- it looks like this is the most robust way to tell if we're
7071 -- looking at exactly this piece of built-in syntax.
71− (atom name, nameStableString name `elem` avoidParensStableNames)
72+ ( atom name
73+ , "$ghc-prim$GHC.Tuple$" `isPrefixOf` nameStableString name
74+ )
7275 if avoidParens
7376 then m
7477 else parensWrapper (backticksWrapper m)
@@ -83,13 +86,3 @@ p_ieWildcard :: IEWildcard -> R ()
8386p_ieWildcard = \case
8487 NoIEWildcard -> return ()
8588 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− ]