on master help sign in
Fix extra layer of parentheses around operator sections
commite00bd3e72a7a728eebc992d1ccdead37808e91f2 authormrkkrp <mark.karpov@tweag.io> dateWed 12 Jun 2019, 16:29 (7 years ago) parent1e6f4cd
3 files changed+17−3
data/examples/declaration/value/function/operator-sections-out.hs+2 data/examples/declaration/value/function/operator-sections.hs+2 src/Ormolu/Printer/Meat/Common.hs+13−3
data/examples/declaration/value/function/operator-sections-out.hs+2
@@ -9,3 +9,5 @@ baz =
99 ( *
1010 3 ^ 5
1111 )
12+
13+quux = (,) <$> foo <$> bar
data/examples/declaration/value/function/operator-sections.hs+2
@@ -5,3 +5,5 @@ baz =
55 + )
66 ( *
77 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
5656 if AnnOpenP `elem` ids
5757 then parens
5858 else id
59− (m, isUnit) =
59+ (m, avoidParens) =
6060 case x of
6161 Unqual occName ->
6262 (atom occName, False)
@@ -68,8 +68,8 @@ p_rdrName l@(L spn _) = located l $ \x -> do
6868 -- NOTE I'm not sure this "stable string" is stable enough, but
6969 -- it looks like this is the most robust way to tell if we're
7070 -- looking at exactly this piece of built-in syntax.
71− (atom name, nameStableString name == "$ghc-prim$GHC.Tuple$()")
72− if isUnit
71+ (atom name, nameStableString name `elem` avoidParensStableNames)
72+ if avoidParens
7373 then m
7474 else parensWrapper (backticksWrapper m)
7575
@@ -83,3 +83,13 @@ p_ieWildcard :: IEWildcard -> R ()
8383p_ieWildcard = \case
8484 NoIEWildcard -> return ()
8585 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+ ]