diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2022-12-04 15:30:21 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-05 05:18:50 -0500 |
commit | 1a767fa359d22ca7637af41e29434e76487c3f21 (patch) | |
tree | 61bf8417aee7d2b2de223a658cda431d26821969 /utils | |
parent | 4251226448f34403b07822f3017845c4855f4dea (diff) | |
download | haskell-1a767fa359d22ca7637af41e29434e76487c3f21.tar.gz |
Add BufSpan to EpaLocation (#22319, #22558)
The key part of this patch is the change to mkTokenLocation:
- mkTokenLocation (RealSrcSpan r _) = TokenLoc (EpaSpan r)
+ mkTokenLocation (RealSrcSpan r mb) = TokenLoc (EpaSpan r mb)
mkTokenLocation used to discard the BufSpan, but now it is saved and can
be retrieved from LHsToken or LHsUniToken.
This is made possible by the following change to EpaLocation:
- data EpaLocation = EpaSpan !RealSrcSpan
+ data EpaLocation = EpaSpan !RealSrcSpan !(Strict.Maybe BufSpan)
| ...
The end goal is to make use of the BufSpan in Parser/PostProcess/Haddock.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/check-exact/ExactPrint.hs | 4 | ||||
-rw-r--r-- | utils/check-exact/Parsers.hs | 2 | ||||
-rw-r--r-- | utils/check-exact/Transform.hs | 12 | ||||
-rw-r--r-- | utils/check-exact/Utils.hs | 6 |
4 files changed, 12 insertions, 12 deletions
diff --git a/utils/check-exact/ExactPrint.hs b/utils/check-exact/ExactPrint.hs index d2005c6733..19548f58ab 100644 --- a/utils/check-exact/ExactPrint.hs +++ b/utils/check-exact/ExactPrint.hs @@ -543,7 +543,7 @@ printStringAtAAL (EpAnn anc an cs) l str = do printStringAtAAC :: (Monad m, Monoid w) => CaptureComments -> EpaLocation -> String -> EP w m EpaLocation -printStringAtAAC capture (EpaSpan r) s = printStringAtRsC capture r s +printStringAtAAC capture (EpaSpan r _) s = printStringAtRsC capture r s printStringAtAAC capture (EpaDelta d cs) s = do mapM_ (printOneComment . tokComment) cs pe1 <- getPriorEndD @@ -4108,7 +4108,7 @@ printUnicode anc n = do s -> s loc <- printStringAtAAC NoCaptureComments (EpaDelta (SameLine 0) []) str case loc of - EpaSpan _ -> return anc + EpaSpan _ _ -> return anc EpaDelta dp [] -> return anc { anchor_op = MovedAnchor dp } EpaDelta _ _cs -> error "printUnicode should not capture comments" diff --git a/utils/check-exact/Parsers.hs b/utils/check-exact/Parsers.hs index 9b9cdd1dd7..695f7f2310 100644 --- a/utils/check-exact/Parsers.hs +++ b/utils/check-exact/Parsers.hs @@ -285,7 +285,7 @@ fixModuleTrailingComments (GHC.L l p) = GHC.L l p' rebalance al cs = cs' where cs' = case GHC.al_close al of - Just (GHC.AddEpAnn _ (GHC.EpaSpan ss)) -> + Just (GHC.AddEpAnn _ (GHC.EpaSpan ss _)) -> let pc = GHC.priorComments cs fc = GHC.getFollowingComments cs diff --git a/utils/check-exact/Transform.hs b/utils/check-exact/Transform.hs index 495b299a47..13c089eb71 100644 --- a/utils/check-exact/Transform.hs +++ b/utils/check-exact/Transform.hs @@ -213,7 +213,7 @@ captureTypeSigSpacing (L l (SigD x (TypeSig (EpAnn anc (AnnSig dc rs') cs) ns (H L (SrcSpanAnn EpAnnNotUsed ll) _ -> realSrcSpan ll L (SrcSpanAnn (EpAnn anc' _ _) _) _ -> anchor anc' -- TODO MovedAnchor? dc' = case dca of - EpaSpan r -> AddEpAnn kw (EpaDelta (ss2delta (ss2posEnd rd) r) []) + EpaSpan r _ -> AddEpAnn kw (EpaDelta (ss2delta (ss2posEnd rd) r) []) EpaDelta _ _ -> AddEpAnn kw dca -- --------------------------------- @@ -223,7 +223,7 @@ captureTypeSigSpacing (L l (SigD x (TypeSig (EpAnn anc (AnnSig dc rs') cs) ns (H (L (SrcSpanAnn EpAnnNotUsed ll) b) -> let op = case dca of - EpaSpan r -> MovedAnchor (ss2delta (ss2posEnd r) (realSrcSpan ll)) + EpaSpan r _ -> MovedAnchor (ss2delta (ss2posEnd r) (realSrcSpan ll)) EpaDelta _ _ -> MovedAnchor (SameLine 1) in (L (SrcSpanAnn (EpAnn (Anchor (realSrcSpan ll) op) mempty emptyComments) ll) b) (L (SrcSpanAnn (EpAnn (Anchor r op) a c) ll) b) @@ -231,7 +231,7 @@ captureTypeSigSpacing (L l (SigD x (TypeSig (EpAnn anc (AnnSig dc rs') cs) ns (H op' = case op of MovedAnchor _ -> op _ -> case dca of - EpaSpan dcr -> MovedAnchor (ss2delta (ss2posEnd dcr) r) + EpaSpan dcr _ -> MovedAnchor (ss2delta (ss2posEnd dcr) r) EpaDelta _ _ -> MovedAnchor (SameLine 1) in (L (SrcSpanAnn (EpAnn (Anchor r op') a c) ll) b) @@ -341,13 +341,13 @@ getEntryDP _ = SameLine 1 addEpaLocationDelta :: LayoutStartCol -> RealSrcSpan -> EpaLocation -> EpaLocation addEpaLocationDelta _off _anc (EpaDelta d cs) = EpaDelta d cs -addEpaLocationDelta off anc (EpaSpan r) +addEpaLocationDelta off anc (EpaSpan r _) = EpaDelta (adjustDeltaForOffset off (ss2deltaEnd anc r)) [] -- Set the entry DP for an element coming after an existing keyword annotation setEntryDPFromAnchor :: LayoutStartCol -> EpaLocation -> LocatedA t -> LocatedA t setEntryDPFromAnchor _off (EpaDelta _ _) (L la a) = L la a -setEntryDPFromAnchor off (EpaSpan anc) ll@(L la _) = setEntryDP ll dp' +setEntryDPFromAnchor off (EpaSpan anc _) ll@(L la _) = setEntryDP ll dp' where r = case la of (SrcSpanAnn EpAnnNotUsed l) -> realSrcSpan l @@ -944,7 +944,7 @@ instance HasDecls (LocatedA (HsExpr GhcPs)) where (L (TokenLoc l) ls, L (TokenLoc i) is) -> let off = case l of - (EpaSpan r) -> LayoutStartCol $ snd $ ss2pos r + (EpaSpan r _) -> LayoutStartCol $ snd $ ss2pos r (EpaDelta (SameLine _) _) -> LayoutStartCol 0 (EpaDelta (DifferentLine _ c) _) -> LayoutStartCol c ex'' = setEntryDPFromAnchor off i ex diff --git a/utils/check-exact/Utils.hs b/utils/check-exact/Utils.hs index abfe598f26..ae98e7bf29 100644 --- a/utils/check-exact/Utils.hs +++ b/utils/check-exact/Utils.hs @@ -119,7 +119,7 @@ undelta (l,_) (DifferentLine dl dc) (LayoutStartCol co) = (fl,fc) fc = co + dc undeltaSpan :: RealSrcSpan -> AnnKeywordId -> DeltaPos -> AddEpAnn -undeltaSpan anchor kw dp = AddEpAnn kw (EpaSpan sp) +undeltaSpan anchor kw dp = AddEpAnn kw (EpaSpan sp Strict.Nothing) where (l,c) = undelta (ss2pos anchor) dp (LayoutStartCol 0) len = length (keywordToString kw) @@ -256,7 +256,7 @@ sortEpaComments cs = sortBy cmp cs -- | Makes a comment which originates from a specific keyword. mkKWComment :: AnnKeywordId -> EpaLocation -> Comment -mkKWComment kw (EpaSpan ss) +mkKWComment kw (EpaSpan ss _) = Comment (keywordToString kw) (Anchor ss UnchangedAnchor) ss (Just kw) mkKWComment kw (EpaDelta dp _) = Comment (keywordToString kw) (Anchor placeholderRealSpan (MovedAnchor dp)) placeholderRealSpan (Just kw) @@ -373,7 +373,7 @@ addEpAnnLoc (AddEpAnn _ l) = l -- TODO: move this to GHC anchorToEpaLocation :: Anchor -> EpaLocation -anchorToEpaLocation (Anchor r UnchangedAnchor) = EpaSpan r +anchorToEpaLocation (Anchor r UnchangedAnchor) = EpaSpan r Strict.Nothing anchorToEpaLocation (Anchor _ (MovedAnchor dp)) = EpaDelta dp [] -- --------------------------------------------------------------------- |