on master help sign in
Fix extra layer of parentheses around operator sections
e00bd3emrkkrp
data/examples/declaration/value/function/operator-sections-out.hs+2
@@ -9,3 +9,5 @@ baz =
9 ( *
9 ( *
10 3 ^ 5
10 3 ^ 5
11 )
11 )
12+
13+quux = (,) <$> foo <$> bar
data/examples/declaration/value/function/operator-sections.hs+2
@@ -5,3 +5,5 @@ baz =
5 + )
5 + )
6 ( *
6 ( *
7 3 ^ 5)
7 3 ^ 5)
8+
9+quux = (,) <$> foo <$> bar
src/Ormolu/Printer/Meat/Common.hs+13−3
@@ -56,7 +56,7 @@ p_rdrName l@(L spn _) = located l $ \x -> do
56 if AnnOpenP `elem` ids
56 if AnnOpenP `elem` ids
57 then parens
57 then parens
58 else id
58 else id
59− (m, isUnit) =
59+ (m, avoidParens) =
60 case x of
60 case x of
61 Unqual occName ->
61 Unqual occName ->
62 (atom occName, False)
62 (atom occName, False)
@@ -68,8 +68,8 @@ p_rdrName l@(L spn _) = located l $ \x -> do
68 -- NOTE I'm not sure this "stable string" is stable enough, but
68 -- 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
69 -- it looks like this is the most robust way to tell if we're
70 -- looking at exactly this piece of built-in syntax.
70 -- looking at exactly this piece of built-in syntax.
71− (atom name, nameStableString name == "$ghc-prim$GHC.Tuple$()")
71+ (atom name, nameStableString name `elem` avoidParensStableNames)
72− if isUnit
72+ if avoidParens
73 then m
73 then m
74 else parensWrapper (backticksWrapper m)
74 else parensWrapper (backticksWrapper m)
75
75
@@ -83,3 +83,13 @@ p_ieWildcard :: IEWildcard -> R ()
83p_ieWildcard = \case
83p_ieWildcard = \case
84 NoIEWildcard -> return ()
84 NoIEWildcard -> return ()
85 IEWildcard n -> parens (atom n)
85 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+ ]