diff --git a/data/15-regressions.blt b/data/15-regressions.blt index 4dacfeb..bf6f340 100644 --- a/data/15-regressions.blt +++ b/data/15-regressions.blt @@ -1066,3 +1066,9 @@ func = func (abc) (def) #expected -- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize } func = func abc def + +#test wandering comment at end of datadecl +data ReformatParenMode + = ReformatParenModeKeep -- don't modify parens at all + | ReformatParenModeClean -- remove unnecessary parens + | ReformatParenModeAll -- add superfluous parens everywhere diff --git a/source/library/Language/Haskell/Brittany/Internal/StepOrchestrate.hs b/source/library/Language/Haskell/Brittany/Internal/StepOrchestrate.hs index ebc3fef..df2ddb1 100644 --- a/source/library/Language/Haskell/Brittany/Internal/StepOrchestrate.hs +++ b/source/library/Language/Haskell/Brittany/Internal/StepOrchestrate.hs @@ -184,15 +184,18 @@ processModule traceFunc conf inlineConf moduleElems = do commentToDoc :: (Int, EpaCommentTok) -> ToBriDocM BriDocNumbered commentToDoc (indent, c) = case c of - GHC.EpaDocCommentNext str -> docLitS (replicate indent ' ' ++ str) - GHC.EpaDocCommentPrev str -> docLitS (replicate indent ' ' ++ str) - GHC.EpaDocCommentNamed str -> docLitS (replicate indent ' ' ++ str) - GHC.EpaDocSection _ str -> docLitS (replicate indent ' ' ++ str) - GHC.EpaDocOptions str -> docLitS (replicate indent ' ' ++ str) - GHC.EpaLineComment str -> docLitS (replicate indent ' ' ++ str) - GHC.EpaBlockComment str -> docLitS (replicate indent ' ' ++ str) + GHC.EpaDocCommentNext str -> handle str + GHC.EpaDocCommentPrev str -> handle str + GHC.EpaDocCommentNamed str -> handle str + GHC.EpaDocSection _ str -> handle str + GHC.EpaDocOptions str -> handle str + GHC.EpaLineComment str -> handle str + GHC.EpaBlockComment str -> handle str GHC.EpaEofComment -> docEmpty - + where + handle str = if indent == 0 + then docLitS str + else docSeq [docSeparator, docLitS $ (replicate (indent - 1) ' ') ++ str ] -- Prints the information associated with the module annotation -- This includes the imports