From 05270ecb456aae12e5241c7f0a7c94a6d3f36e2d Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Sun, 26 Mar 2023 20:20:45 +0000 Subject: [PATCH] Improve block-comment behaviour (newlines after or not) --- data/11-extensions/overloadedrecorddot.blt | 2 +- .../Internal/WriteBriDoc/Operators.hs | 44 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/data/11-extensions/overloadedrecorddot.blt b/data/11-extensions/overloadedrecorddot.blt index 7586a9d..7c8d564 100644 --- a/data/11-extensions/overloadedrecorddot.blt +++ b/data/11-extensions/overloadedrecorddot.blt @@ -7,7 +7,7 @@ recorddot1 = a.b.c #test getfield {-# LANGUAGE OverloadedRecordDot #-} recorddot2 = - {-before-}a.b.c{-after-} + {-before-} a.b.c {-after-} #test projection {-# LANGUAGE OverloadedRecordDot #-} diff --git a/source/library/Language/Haskell/Brittany/Internal/WriteBriDoc/Operators.hs b/source/library/Language/Haskell/Brittany/Internal/WriteBriDoc/Operators.hs index 64530ad..2ef7a15 100644 --- a/source/library/Language/Haskell/Brittany/Internal/WriteBriDoc/Operators.hs +++ b/source/library/Language/Haskell/Brittany/Internal/WriteBriDoc/Operators.hs @@ -119,24 +119,42 @@ layoutWriteComment -> m () layoutWriteComment absolute isBlock dp commentLines s = do -- TODO92 we don't move to comment pos at all! let (y, x) = case dp of - GHC.SameLine c -> (0, c) - GHC.DifferentLine l c -> (l, c) + GHC.SameLine c -> (0, c) + GHC.DifferentLine l c -> (l, c) state <- mGet - mTell $ Text.Builder.fromString $ replicate y '\n' ++ replicate (if absolute && (y > 0) then x-1 else x) ' ' + mTell $ Text.Builder.fromString $ replicate y '\n' ++ replicate + (if absolute && (y > 0) then x - 1 else x) + ' ' mTell $ Text.Builder.fromText s - traceLocal ("layoutMoveToCommentPos", y, x, commentLines, _lstate_plannedSpace state, lstate_baseY state) + traceLocal + ( "layoutMoveToCommentPos" + , y + , x + , commentLines + , _lstate_plannedSpace state + , lstate_baseY state + ) mSet state - { _lstate_plannedSpace = if isBlock - then PlannedSameline 0 + { _lstate_plannedSpace = if isBlock + then case _lstate_plannedSpace state of + PlannedNone -> PlannedSameline 1 + p@PlannedSameline{} -> p + PlannedNewline l -> + if l <= y then PlannedSameline 1 else PlannedNewline (l - y) + PlannedDelta l i -> + if l <= y then PlannedSameline 1 else PlannedDelta (l - y) i else case _lstate_plannedSpace state of - PlannedNone -> PlannedDelta 1 (_lstate_curY state) - PlannedSameline i -> PlannedDelta 1 (_lstate_curY state + i) + PlannedNone -> PlannedDelta 1 (_lstate_curY state) + PlannedSameline i -> PlannedDelta 1 (_lstate_curY state + i) p@PlannedNewline{} -> p - p@PlannedDelta{} -> p - , _lstate_commentNewlines = - _lstate_commentNewlines state + y + commentLines - 1 - , _lstate_curY = if y == 0 then _lstate_curY state + x + Text.length s - else x + Text.length s + p@PlannedDelta{} -> p + , _lstate_commentNewlines = _lstate_commentNewlines state + + y + + commentLines + - 1 + , _lstate_curY = if y == 0 + then _lstate_curY state + x + Text.length s + else x + Text.length s }