1
1
mirror of https://github.com/github/semantic.git synced 2024-12-18 12:21:57 +03:00

Adjoin expects breaks at the end of lines.

This commit is contained in:
Rob Rix 2015-12-10 13:17:09 -05:00
parent d1018576fd
commit 72fef55675

View File

@ -188,18 +188,18 @@ maybeLast list = listToMaybe $ reverse list
adjoin2 :: [Row] -> Row -> [Row]
adjoin2 [] row = [row]
-- handle the case where we append a newline on both sides
adjoin2 rows (Row left@(Line (Break : _)) right@(Line (Break : _))) = Row left right : rows
adjoin2 rows (Row left@(Line (Break : _)) right) = Row left EmptyLine : zipWith Row lefts rights
where
lefts = leftLines rows
rights = adjoin2Lines (rightLines rows) right
adjoin2 rows (Row left right@(Line (Break : _))) = Row EmptyLine right : zipWith Row lefts rights
where
lefts = adjoin2Lines (leftLines rows) left
rights = rightLines rows
adjoin2 (Row EmptyLine EmptyLine : init) row = adjoin2 init row
adjoin2 rows@(Row left right:_) row | Just Break <- maybeLast $ unLine left, Just Break <- maybeLast $ unLine right = row : rows
adjoin2 rows@(Row left _:_) (Row left' right') | Just Break <- maybeLast $ unLine left = Row left' EmptyLine : zipWith Row lefts rights
where lefts = leftLines rows
rights = adjoin2Lines (rightLines rows) right'
adjoin2 rows@(Row _ right:_) (Row left' right') | Just Break <- maybeLast $ unLine right = Row EmptyLine right' : zipWith Row lefts rights
where lefts = adjoin2Lines (leftLines rows) left'
rights = rightLines rows
adjoin2 (Row EmptyLine EmptyLine : rows) row = adjoin2 rows row
adjoin2 rows (Row left right) = zipWith Row lefts rights
where