Fix non-idempotent newlines with comment + where (#263)

api
Lennart Spitzner 2019-12-20 01:12:25 +01:00
parent 434854f8f3
commit 6724760f40
5 changed files with 30 additions and 5 deletions

View File

@ -770,3 +770,15 @@ vakjkeSulxudbFokvir = Duotpo
, -- N.B.
.. -- x
}
#test issue 263
func = abc + def
-- a
-- b
-- comment
where
abc = 13
def = 1

View File

@ -651,6 +651,7 @@ layoutBriDoc briDoc = do
, _lstate_comments = anns
, _lstate_commentCol = Nothing
, _lstate_addSepSpace = Nothing
, _lstate_commentNewlines = 0
}
state' <- MultiRWSS.withMultiStateS state $ layoutBriDocM briDoc'

View File

@ -279,12 +279,14 @@ layoutBriDocM = \case
, keyword == kw1
]
-- mTell $ Seq.fromList ["KWDP: " ++ show annKey ++ " " ++ show mAnn]
pure $ case relevant of
[] -> Nothing
(dp:_) -> Just dp
case relevant of
[] -> pure Nothing
(ExactPrint.Types.DP (y, x):_) -> do
mSet state { _lstate_commentNewlines = 0 }
pure $ Just (y - _lstate_commentNewlines state, x)
case mDP of
Nothing -> pure ()
Just (ExactPrint.Types.DP (y, x)) ->
Just (y, x) ->
layoutMoveToCommentPos y (if shouldRestoreIndent then x else 0)
layoutBriDocM bd
BDNonBottomSpacing _ bd -> layoutBriDocM bd

View File

@ -200,6 +200,7 @@ layoutMoveToCommentPos y x = do
Nothing -> case _lstate_curYOrAddNewline state of
Left i -> i + fromMaybe 0 (_lstate_addSepSpace state)
Right{} -> lstate_baseY state
, _lstate_commentNewlines = _lstate_commentNewlines state + y
}
-- | does _not_ add spaces to again reach the current base column.
@ -217,6 +218,7 @@ layoutWriteNewline = do
Left{} -> Right 1
Right i -> Right (i + 1)
, _lstate_addSepSpace = Nothing
, _lstate_commentNewlines = 0
}
layoutWriteEnsureNewlineBlock
@ -574,7 +576,9 @@ layoutIndentRestorePostComment = do
#if INSERTTRACES
tellDebugMessShow ("layoutIndentRestorePostComment", mCommentCol)
#endif
mModify $ \s -> s { _lstate_commentCol = Nothing }
mModify $ \s -> s { _lstate_commentCol = Nothing
, _lstate_commentNewlines = 0
}
case (mCommentCol, eCurYAddNL) of
(Just commentCol, Left{}) -> do
layoutWriteEnsureNewlineBlock

View File

@ -84,6 +84,11 @@ data LayoutState = LayoutState
-- -- captures if the layouter currently is in a new line, i.e. if the
-- -- current line only contains (indentation) spaces.
-- this is mostly superseeded by curYOrAddNewline, iirc.
, _lstate_commentNewlines :: Int -- number of newlines inserted due to
-- move-to-DP at a start of a comment.
-- Necessary because some keyword DPs
-- are relative to the last non-comment
-- entity (for some reason)
}
lstate_baseY :: LayoutState -> Int
@ -102,6 +107,7 @@ instance Show LayoutState where
++ ",indLevelLinger=" ++ show (_lstate_indLevelLinger state)
++ ",commentCol=" ++ show (_lstate_commentCol state)
++ ",addSepSpace=" ++ show (_lstate_addSepSpace state)
++ ",commentNewlines=" ++ show (_lstate_commentNewlines state)
++ "}"
-- data NewLineState = NewLineStateInit -- initial state. we do not know if in a