diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2017-02-27 11:43:01 +0200 |
---|---|---|
committer | Alan Zimmerman <alan.zimm@gmail.com> | 2017-02-27 11:46:52 +0200 |
commit | c0af206f26b97d8d4f1c5722825577b27087c0a9 (patch) | |
tree | 3796ca99b4f608a0d8d7d2d39b80b968337debed /compiler/hsSyn/HsExpr.hs | |
parent | 76f2cd02ab04818f19be1927c2a640dede3e9dd3 (diff) | |
download | haskell-c0af206f26b97d8d4f1c5722825577b27087c0a9.tar.gz |
Explicitly capture whether a splice has a dollar prefix
A top-level splice can be written
$splice
or
splice
For accurate pretty-printing, and for ghc-exactprint, capture in the hsSyn AST
which variant was parsed.
Diffstat (limited to 'compiler/hsSyn/HsExpr.hs')
-rw-r--r-- | compiler/hsSyn/HsExpr.hs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/compiler/hsSyn/HsExpr.hs b/compiler/hsSyn/HsExpr.hs index de793bd6d5..f627056d17 100644 --- a/compiler/hsSyn/HsExpr.hs +++ b/compiler/hsSyn/HsExpr.hs @@ -2045,12 +2045,12 @@ pprQuals quals = interpp'SP quals -- | Haskell Splice data HsSplice id = HsTypedSplice -- $$z or $$(f 4) - HasParens -- Whether $$( ) variant found, for pretty printing + SpliceDecoration -- Whether $$( ) variant found, for pretty printing id -- A unique name to identify this splice point (LHsExpr id) -- See Note [Pending Splices] | HsUntypedSplice -- $z or $(f 4) - HasParens -- Whether $( ) variant found, for pretty printing + SpliceDecoration -- Whether $( ) variant found, for pretty printing id -- A unique name to identify this splice point (LHsExpr id) -- See Note [Pending Splices] @@ -2070,13 +2070,17 @@ data HsSplice id deriving Typeable deriving instance (DataId id) => Data (HsSplice id) -data HasParens = HasParens - | NoParens - deriving (Data, Eq, Show) +-- | A splice can appear with various decorations wrapped around it. This data +-- type captures explicitly how it was originally written, for use in the pretty +-- printer. +data SpliceDecoration + = HasParens -- ^ $( splice ) or $$( splice ) + | HasDollar -- ^ $splice or $$splice + | NoParens -- ^ bare splice + deriving (Data, Eq, Show) -instance Outputable HasParens where - ppr HasParens = text "HasParens" - ppr NoParens = text "NoParens" +instance Outputable SpliceDecoration where + ppr x = text $ show x isTypedSplice :: HsSplice id -> Bool @@ -2218,12 +2222,16 @@ ppr_splice_decl e = pprSplice e pprSplice :: (OutputableBndrId id) => HsSplice id -> SDoc pprSplice (HsTypedSplice HasParens n e) = ppr_splice (text "$$(") n e (text ")") -pprSplice (HsTypedSplice NoParens n e) +pprSplice (HsTypedSplice HasDollar n e) = ppr_splice (text "$$") n e empty +pprSplice (HsTypedSplice NoParens n e) + = ppr_splice empty n e empty pprSplice (HsUntypedSplice HasParens n e) = ppr_splice (text "$(") n e (text ")") -pprSplice (HsUntypedSplice NoParens n e) +pprSplice (HsUntypedSplice HasDollar n e) = ppr_splice (text "$") n e empty +pprSplice (HsUntypedSplice NoParens n e) + = ppr_splice empty n e empty pprSplice (HsQuasiQuote n q _ s) = ppr_quasi n q s pprSplice (HsSpliced _ thing) = ppr thing |