diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/Parser.y | 6 | ||||
-rw-r--r-- | compiler/GHC/Parser/PostProcess.hs | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y index 01c0459866..bb57f39d7b 100644 --- a/compiler/GHC/Parser.y +++ b/compiler/GHC/Parser.y @@ -3318,10 +3318,10 @@ apats :: { [LPat GhcPs] } -- Statement sequences stmtlist :: { forall b. DisambECP b => PV (LocatedL [LocatedA (Stmt GhcPs (LocatedA b))]) } - : '{' stmts '}' { $2 >>= \ $2 -> amsrl - (sLL $1 $> (reverse $ snd $ unLoc $2)) (AnnList (Just $ glR $2) (Just $ moc $1) (Just $ mcc $3) (fromOL $ fst $ unLoc $2) []) } + : '{' stmts '}' { $2 >>= \ $2 -> + amsrl (sLL $1 $> (reverse $ snd $ unLoc $2)) (AnnList (Just $ stmtsAnchor $2) (Just $ moc $1) (Just $ mcc $3) (fromOL $ fst $ unLoc $2) []) } | vocurly stmts close { $2 >>= \ $2 -> amsrl - (L (gl $2) (reverse $ snd $ unLoc $2)) (AnnList (Just $ glR $2) Nothing Nothing (fromOL $ fst $ unLoc $2) []) } + (L (stmtsLoc $2) (reverse $ snd $ unLoc $2)) (AnnList (Just $ stmtsAnchor $2) Nothing Nothing (fromOL $ fst $ unLoc $2) []) } -- do { ;; s ; s ; ; s ;; } -- The last Stmt should be an expression, but that's hard to enforce diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 8a89bef84d..845f7eb25c 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -39,6 +39,7 @@ module GHC.Parser.PostProcess ( fromSpecTyVarBndr, fromSpecTyVarBndrs, annBinds, fixValbindsAnn, + stmtsAnchor, stmtsLoc, cvBindGroup, cvBindsAndSigs, @@ -478,6 +479,18 @@ fixValbindsAnn EpAnnNotUsed = EpAnnNotUsed fixValbindsAnn (EpAnn anchor (AnnList ma o c r t) cs) = (EpAnn (widenAnchor anchor (map trailingAnnToAddEpAnn t)) (AnnList ma o c r t) cs) +-- | The 'Anchor' for a stmtlist is based on either the location or +-- the first semicolon annotion. +stmtsAnchor :: Located (OrdList AddEpAnn,a) -> Anchor +stmtsAnchor (L l ((ConsOL (AddEpAnn _ (EpaSpan r)) _), _)) + = widenAnchorR (Anchor (realSrcSpan l) UnchangedAnchor) r +stmtsAnchor (L l _) = Anchor (realSrcSpan l) UnchangedAnchor + +stmtsLoc :: Located (OrdList AddEpAnn,a) -> SrcSpan +stmtsLoc (L l ((ConsOL aa _), _)) + = widenSpan l [aa] +stmtsLoc (L l _) = l + {- ********************************************************************** #cvBinds-etc# Converting to @HsBinds@, etc. |