hindent-6.0.0: Extensible Haskell pretty printer
Safe HaskellSafe-Inferred
LanguageHaskell2010

HIndent.ModulePreprocessing.CommentRelocation

Description

Comment relocation for pretty-printing comments correctly.

HIndent gathers all comments above a function, an import, a module declaration, etc. For example, HIndent formats the following code

f :: Int
f = 1

-- A comment between f and g

-- Another comment between f and g

g :: Int
g = 2

to

f :: Int
f = 1

-- A comment between f and g
-- Another comment between f and g
g :: Int
g = 2

AST nodes must have the information of which comments are above, on the same line, and below. However, AST nodes generated by a parser of 'ghc-lib-parser' only contain comments after them. relocateComments is defined to solve the problem.

Synopsis

Documentation

relocateComments :: HsModule -> [LEpaComment] -> HsModule Source #

This function collects all comments from the passed HsModule, and modifies all EpAnns so that all EpAnns have EpaCommentsBalanceds.