@@ -103,7 +103,7 @@ mkComment ::
103103mkComment ls (L l s) = (ls', comment)
104104 where
105105 comment =
106− L l . Comment atomsBefore . fmap dropTrailing $
106+ L l . Comment atomsBefore . removeConseqBlanks . fmap dropTrailing $
107107 if "{-" `L.isPrefixOf` s
108108 then case NE.nonEmpty (lines s) of
109109 Nothing -> s :| []
@@ -143,26 +143,6 @@ isMultilineComment (Comment _ (x :| _)) = "{-" `L.isPrefixOf` x
143143----------------------------------------------------------------------------
144144-- Helpers
145145
146−-- | Get a 'String' from 'GHC.AnnotationComment'.
147−unAnnotationComment :: GHC.AnnotationComment -> Maybe String
148−unAnnotationComment = \case
149− GHC.AnnDocCommentNext _ -> Nothing -- @-- |@
150− GHC.AnnDocCommentPrev _ -> Nothing -- @-- ^@
151− GHC.AnnDocCommentNamed _ -> Nothing -- @-- $@
152− GHC.AnnDocSection _ _ -> Nothing -- @-- *@
153− GHC.AnnDocOptions s -> Just s
154− GHC.AnnLineComment s -> Just s
155− GHC.AnnBlockComment s -> Just s
156−
157−liftMaybe :: Located (Maybe a) -> Maybe (Located a)
158−liftMaybe = \case
159− L _ Nothing -> Nothing
160− L l (Just a) -> Just (L l a)
161−
162−toRealSpan :: Located a -> Maybe (RealLocated a)
163−toRealSpan (L (RealSrcSpan l) a) = Just (L l a)
164−toRealSpan _ = Nothing
165−
166146-- | Detect and extract stack header if it is present.
167147extractStackHeader ::
168148 [RealLocated String] ->
@@ -196,3 +176,34 @@ extractPragmas input = go initialLs id id
196176 Just pragma ->
197177 let combined = (csSoFar [], pragma)
198178 in go ls id (pragmasSoFar . (combined :)) xs
179+
180+-- | Get a 'String' from 'GHC.AnnotationComment'.
181+unAnnotationComment :: GHC.AnnotationComment -> Maybe String
182+unAnnotationComment = \case
183+ GHC.AnnDocCommentNext _ -> Nothing -- @-- |@
184+ GHC.AnnDocCommentPrev _ -> Nothing -- @-- ^@
185+ GHC.AnnDocCommentNamed _ -> Nothing -- @-- $@
186+ GHC.AnnDocSection _ _ -> Nothing -- @-- *@
187+ GHC.AnnDocOptions s -> Just s
188+ GHC.AnnLineComment s -> Just s
189+ GHC.AnnBlockComment s -> Just s
190+
191+liftMaybe :: Located (Maybe a) -> Maybe (Located a)
192+liftMaybe = \case
193+ L _ Nothing -> Nothing
194+ L l (Just a) -> Just (L l a)
195+
196+toRealSpan :: Located a -> Maybe (RealLocated a)
197+toRealSpan (L (RealSrcSpan l) a) = Just (L l a)
198+toRealSpan _ = Nothing
199+
200+-- | Remove consecutive blank lines.
201+removeConseqBlanks :: NonEmpty String -> NonEmpty String
202+removeConseqBlanks (x :| xs) = x :| go (null x) id xs
203+ where
204+ go seenBlank acc = \case
205+ [] -> acc []
206+ (y : ys) ->
207+ if seenBlank && null y
208+ then go True acc ys
209+ else go (null y) (acc . (y :)) ys