1
1
mirror of https://github.com/github/semantic.git synced 2025-01-06 06:46:07 +03:00

Move adjoinRowsBy into the Row module.

This commit is contained in:
Rob Rix 2015-12-22 17:27:56 -05:00
parent c92ba49b4d
commit b165994569
2 changed files with 24 additions and 23 deletions

View File

@ -5,5 +5,29 @@ import Line
data Row a = Row { unLeft :: Line a, unRight :: Line a }
deriving (Eq, Functor)
adjoinRowsBy :: (a -> Maybe a) -> (a -> Maybe a) -> [Row a] -> Row a -> [Row a]
adjoinRowsBy _ _ [] row = [row]
adjoinRowsBy f g rows (Row left' right') | Just _ <- openLineBy f $ unLeft <$> rows, Just _ <- openLineBy g $ unRight <$> rows = zipWith Row lefts rights
where lefts = adjoinLinesBy f (unLeft <$> rows) left'
rights = adjoinLinesBy g (unRight <$> rows) right'
adjoinRowsBy f _ rows (Row left' right') | Just _ <- openLineBy f $ unLeft <$> rows = case right' of
EmptyLine -> rest
_ -> Row EmptyLine right' : rest
where rest = zipWith Row lefts rights
lefts = adjoinLinesBy f (unLeft <$> rows) left'
rights = unRight <$> rows
adjoinRowsBy _ g rows (Row left' right') | Just _ <- openLineBy g $ unRight <$> rows = case left' of
EmptyLine -> rest
_ -> Row left' EmptyLine : rest
where rest = zipWith Row lefts rights
lefts = unLeft <$> rows
rights = adjoinLinesBy g (unRight <$> rows) right'
adjoinRowsBy _ _ rows row = row : rows
instance Show a => Show (Row a) where
show (Row left right) = "\n" ++ show left ++ " | " ++ show right

View File

@ -129,29 +129,6 @@ splitAnnotatedByLines sources ranges categories syntax = case syntax of
contextLines :: (Info -> a) -> Range -> Set.Set Category -> String -> [Line a]
contextLines constructor range categories source = Line . (:[]) . constructor . (`Info` categories) <$> actualLineRanges range source
adjoinRowsBy :: (a -> Maybe a) -> (a -> Maybe a) -> [Row a] -> Row a -> [Row a]
adjoinRowsBy _ _ [] row = [row]
adjoinRowsBy f g rows (Row left' right') | Just _ <- openLineBy f $ unLeft <$> rows, Just _ <- openLineBy g $ unRight <$> rows = zipWith Row lefts rights
where lefts = adjoinLinesBy f (unLeft <$> rows) left'
rights = adjoinLinesBy g (unRight <$> rows) right'
adjoinRowsBy f _ rows (Row left' right') | Just _ <- openLineBy f $ unLeft <$> rows = case right' of
EmptyLine -> rest
_ -> Row EmptyLine right' : rest
where rest = zipWith Row lefts rights
lefts = adjoinLinesBy f (unLeft <$> rows) left'
rights = unRight <$> rows
adjoinRowsBy _ g rows (Row left' right') | Just _ <- openLineBy g $ unRight <$> rows = case left' of
EmptyLine -> rest
_ -> Row left' EmptyLine : rest
where rest = zipWith Row lefts rights
lefts = unLeft <$> rows
rights = adjoinLinesBy g (unRight <$> rows) right'
adjoinRowsBy _ _ rows row = row : rows
openRange :: String -> Range -> Maybe Range
openRange source range = case (source !!) <$> maybeLastIndex range of
Just '\n' -> Nothing