on master help sign in
Fix rendering of value-level units
commite98df37597439ff9e298035e7f6f6a282e7ce720 authormrkkrp <mark.karpov@tweag.io> dateMon 10 Jun 2019, 21:17 (7 years ago) parent4b1d31e
3 files changed+21−10
data/examples/declaration/value/function/builtin-syntax-out.hs+1 data/examples/declaration/value/function/builtin-syntax.hs+1 src/Ormolu/Printer/Meat/Common.hs+19−10
data/examples/declaration/value/function/builtin-syntax-out.hsnew file+1
@@ -0,0 +1 @@
1+x = return ()
data/examples/declaration/value/function/builtin-syntax.hsnew file+1
@@ -0,0 +1 @@
1+x = return ()
src/Ormolu/Printer/Meat/Common.hs+19−10
@@ -15,10 +15,10 @@ where
1515
1616import GHC hiding (GhcPs, IE)
1717import Module (Module (..))
18+import Name (nameStableString)
1819import OccName (OccName (..))
1920import Ormolu.Printer.Combinators
2021import Ormolu.Printer.Internal (getAnns)
21−import Ormolu.Utils (getSpan)
2222import RdrName (RdrName (..))
2323
2424-- | Data and type family style.
@@ -45,8 +45,8 @@ p_ieWrappedName = \case
4545-- | Render a @'Located' 'RdrName'@.
4646
4747p_rdrName :: Located RdrName -> R ()
48−p_rdrName l = located l $ \x -> do
49− ids <- getAnns (getSpan l)
48+p_rdrName l@(L spn _) = located l $ \x -> do
49+ ids <- getAnns spn
5050 -- NOTE Right now we're mainly interested in backticks and parentheses.
5151 let backticksWrapper =
5252 if AnnBackquote `elem` ids
@@ -56,13 +56,22 @@ p_rdrName l = located l $ \x -> do
5656 if AnnOpenP `elem` ids
5757 then parens
5858 else id
59− -- TODO Check if it's possible to detect simple quoting here as well.
60− parensWrapper . backticksWrapper $
61− case x of
62− Unqual occName -> atom occName
63− Qual mname occName -> p_qualName mname occName
64− Orig (Module _ mname) occName -> p_qualName mname occName
65− Exact name -> atom name
59+ (m, isUnit) =
60+ case x of
61+ Unqual occName ->
62+ (atom occName, False)
63+ Qual mname occName ->
64+ (p_qualName mname occName, False)
65+ Orig (Module _ mname) occName ->
66+ (p_qualName mname occName, False)
67+ Exact name ->
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
70+ -- looking at exactly this piece of built-in syntax.
71+ (atom name, nameStableString name == "$ghc-prim$GHC.Tuple$()")
72+ if isUnit
73+ then m
74+ else parensWrapper (backticksWrapper m)
6675
6776p_qualName :: ModuleName -> OccName -> R ()
6877p_qualName mname occName = do