1
1
mirror of https://github.com/google/ormolu.git synced 2024-11-27 13:13:23 +03:00

Fix extra layer of parentheses around operator sections

This commit is contained in:
mrkkrp 2019-06-12 16:29:53 +02:00 committed by Mark Karpov
parent 1e6f4cdc95
commit e00bd3e72a
3 changed files with 17 additions and 3 deletions

View File

@ -9,3 +9,5 @@ baz =
( *
3 ^ 5
)
quux = (,) <$> foo <$> bar

View File

@ -5,3 +5,5 @@ baz =
+ )
( *
3 ^ 5)
quux = (,) <$> foo <$> bar

View File

@ -56,7 +56,7 @@ p_rdrName l@(L spn _) = located l $ \x -> do
if AnnOpenP `elem` ids
then parens
else id
(m, isUnit) =
(m, avoidParens) =
case x of
Unqual occName ->
(atom occName, False)
@ -68,8 +68,8 @@ p_rdrName l@(L spn _) = located l $ \x -> do
-- NOTE I'm not sure this "stable string" is stable enough, but
-- it looks like this is the most robust way to tell if we're
-- looking at exactly this piece of built-in syntax.
(atom name, nameStableString name == "$ghc-prim$GHC.Tuple$()")
if isUnit
(atom name, nameStableString name `elem` avoidParensStableNames)
if avoidParens
then m
else parensWrapper (backticksWrapper m)
@ -83,3 +83,13 @@ p_ieWildcard :: IEWildcard -> R ()
p_ieWildcard = \case
NoIEWildcard -> return ()
IEWildcard n -> parens (atom n)
avoidParensStableNames :: [String]
avoidParensStableNames =
[ "$ghc-prim$GHC.Tuple$()"
, "$ghc-prim$GHC.Tuple$(,)"
, "$ghc-prim$GHC.Tuple$(,,)"
, "$ghc-prim$GHC.Tuple$(,,,)"
, "$ghc-prim$GHC.Tuple$(,,,,)"
, "$ghc-prim$GHC.Tuple$(,,,,,)"
]