Refactor WriteBriDoc FlushCommentsPrior code slightly

ghc92
Lennart Spitzner 2023-04-24 15:40:15 +00:00
parent d2a48ba559
commit 556bc896a6
1 changed files with 16 additions and 18 deletions

View File

@ -277,24 +277,22 @@ layoutBriDocM = \case
comms <- takeBefore loc comms <- takeBefore loc
printComments comms printComments comms
mModify (\s -> s + CommentCounter (length comms)) mModify (\s -> s + CommentCounter (length comms))
do mModify $ \s -> s
state <- mGet { _lstate_markerForDelta = Nothing
mModify $ \s -> s { _lstate_markerForDelta = Nothing } , _lstate_plannedSpace = case _lstate_markerForDelta s of
case _lstate_markerForDelta state of Nothing -> _lstate_plannedSpace s
Just m -> do Just m ->
let p1 = (srcLocLine m, srcLocCol m) let p1 = (srcLocLine m, srcLocCol m)
let p2 = (srcLocLine loc, srcLocCol loc) p2 = (srcLocLine loc, srcLocCol loc)
let newlinePlanned = case _lstate_plannedSpace state of
PlannedNone -> False
PlannedSameline{} -> False
PlannedNewline{} -> True
PlannedDelta{} -> True
-- traceShow (m, ExactPrint.pos2delta p1 p2) $ pure () -- traceShow (m, ExactPrint.pos2delta p1 p2) $ pure ()
case ExactPrint.pos2delta p1 p2 of in case ExactPrint.pos2delta p1 p2 of
SameLine{} -> pure () SameLine{} -> _lstate_plannedSpace s
DifferentLine n _ | newlinePlanned -> layoutWriteNewlines n DifferentLine n _ -> case _lstate_plannedSpace s of
| otherwise -> pure () PlannedNone -> PlannedNone
_ -> pure () PlannedSameline i -> PlannedSameline i
PlannedNewline{} -> PlannedNewline n
PlannedDelta{} -> PlannedNewline n
}
layoutBriDocM bd layoutBriDocM bd
BDFlushCommentsPost loc shouldMark bd -> do BDFlushCommentsPost loc shouldMark bd -> do
layoutBriDocM bd layoutBriDocM bd