diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2021-08-22 09:13:30 +0100 |
---|---|---|
committer | Alan Zimmerman <alan.zimm@gmail.com> | 2021-09-07 18:19:46 +0100 |
commit | 7b1917c1b996a869c0fb277c6ade3b88b02eb02d (patch) | |
tree | 28e1ea292ab1f56be691ef36c4429c18115191d5 /compiler | |
parent | 6ea9b3ee4454b87ecc017d89f131a80f57ef65aa (diff) | |
download | haskell-wip/az/T20243-n-plus-k-patterns.tar.gz |
EPA: Capture '+' location for NPlusKPatwip/az/T20243-n-plus-k-patterns
The location of the plus symbol was being discarded, we now capture
it.
Closes #20243
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/Hs/Dump.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Hs/Pat.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Hs/Utils.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Parser/Annotation.hs | 6 | ||||
-rw-r--r-- | compiler/GHC/Parser/PostProcess.hs | 7 |
5 files changed, 15 insertions, 6 deletions
diff --git a/compiler/GHC/Hs/Dump.hs b/compiler/GHC/Hs/Dump.hs index 9be0f96640..247e8099da 100644 --- a/compiler/GHC/Hs/Dump.hs +++ b/compiler/GHC/Hs/Dump.hs @@ -62,6 +62,7 @@ showAstData bs ba a0 = blankLine $$ showAstData' a0 `extQ` annotationEpAnnImportDecl `extQ` annotationAnnParen `extQ` annotationTrailingAnn + `extQ` annotationEpaLocation `extQ` addEpAnn `extQ` lit `extQ` litr `extQ` litt `extQ` sourceText @@ -254,6 +255,9 @@ showAstData bs ba a0 = blankLine $$ showAstData' a0 annotationTrailingAnn :: EpAnn TrailingAnn -> SDoc annotationTrailingAnn = annotation' (text "EpAnn TrailingAnn") + annotationEpaLocation :: EpAnn EpaLocation -> SDoc + annotationEpaLocation = annotation' (text "EpAnn EpaLocation") + annotation' :: forall a .(Data a, Typeable a) => SDoc -> EpAnn a -> SDoc annotation' tag anns = case ba of diff --git a/compiler/GHC/Hs/Pat.hs b/compiler/GHC/Hs/Pat.hs index f300c4a2ca..a4b3bed851 100644 --- a/compiler/GHC/Hs/Pat.hs +++ b/compiler/GHC/Hs/Pat.hs @@ -147,7 +147,7 @@ type instance XNPat GhcPs = EpAnn [AddEpAnn] type instance XNPat GhcRn = EpAnn [AddEpAnn] type instance XNPat GhcTc = Type -type instance XNPlusKPat GhcPs = EpAnn [AddEpAnn] +type instance XNPlusKPat GhcPs = EpAnn EpaLocation -- Of the "+" type instance XNPlusKPat GhcRn = NoExtField type instance XNPlusKPat GhcTc = Type diff --git a/compiler/GHC/Hs/Utils.hs b/compiler/GHC/Hs/Utils.hs index 87fc46ff12..ac73720456 100644 --- a/compiler/GHC/Hs/Utils.hs +++ b/compiler/GHC/Hs/Utils.hs @@ -309,7 +309,7 @@ mkHsCompAnns :: HsDoFlavour -> [ExprLStmt GhcPs] -> LHsExpr GhcPs mkNPat :: Located (HsOverLit GhcPs) -> Maybe (SyntaxExpr GhcPs) -> EpAnn [AddEpAnn] -> Pat GhcPs -mkNPlusKPat :: LocatedN RdrName -> Located (HsOverLit GhcPs) -> EpAnn [AddEpAnn] +mkNPlusKPat :: LocatedN RdrName -> Located (HsOverLit GhcPs) -> EpAnn EpaLocation -> Pat GhcPs -- NB: The following functions all use noSyntaxExpr: the generated expressions diff --git a/compiler/GHC/Parser/Annotation.hs b/compiler/GHC/Parser/Annotation.hs index 19925b0678..a914a14b71 100644 --- a/compiler/GHC/Parser/Annotation.hs +++ b/compiler/GHC/Parser/Annotation.hs @@ -13,7 +13,7 @@ module GHC.Parser.Annotation ( -- * In-tree Exact Print Annotations AddEpAnn(..), - EpaLocation(..), epaLocationRealSrcSpan, + EpaLocation(..), epaLocationRealSrcSpan, epaLocationFromSrcAnn, DeltaPos(..), deltaPos, getDeltaLine, EpAnn(..), Anchor(..), AnchorOperation(..), @@ -440,6 +440,10 @@ epaLocationRealSrcSpan :: EpaLocation -> RealSrcSpan epaLocationRealSrcSpan (EpaSpan r) = r epaLocationRealSrcSpan (EpaDelta _) = panic "epaLocationRealSrcSpan" +epaLocationFromSrcAnn :: SrcAnn ann -> EpaLocation +epaLocationFromSrcAnn (SrcSpanAnn EpAnnNotUsed l) = EpaSpan (realSrcSpan l) +epaLocationFromSrcAnn (SrcSpanAnn (EpAnn anc _ _) _) = EpaSpan (anchor anc) + instance Outputable EpaLocation where ppr (EpaSpan r) = text "EpaSpan" <+> ppr r ppr (EpaDelta d) = text "EpaDelta" <+> ppr d diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 4eab0c1486..d1ec88f7fa 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -1146,11 +1146,12 @@ checkAPat loc e0 = do -- n+k patterns PatBuilderOpApp (L _ (PatBuilderVar (L nloc n))) - (L _ plus) + (L l plus) (L lloc (PatBuilderOverLit lit@(OverLit {ol_val = HsIntegral {}}))) - anns + (EpAnn anc _ cs) | nPlusKPatterns && (plus == plus_RDR) - -> return (mkNPlusKPat (L nloc n) (L (locA lloc) lit) anns) + -> return (mkNPlusKPat (L nloc n) (L (locA lloc) lit) + (EpAnn anc (epaLocationFromSrcAnn l) cs)) -- Improve error messages for the @-operator when the user meant an @-pattern PatBuilderOpApp _ op _ _ | opIsAt (unLoc op) -> do |