1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 18:36:27 +03:00

Abstract the constructor over the patch.

This commit is contained in:
Rob Rix 2016-03-03 12:30:23 -05:00
parent ff31489bce
commit 7a03c23018

View File

@ -50,8 +50,11 @@ splitPatchByLines patch previous sources = case patch of
(makeRow EmptyLine . fmap (Pure . SplitInsert) <$> lines, both (rangeAt $ fst previous) range)
Delete term -> let (lines, range) = splitAbstractedTerm copoint unwrap (:<) (fst sources) term in
(flip makeRow EmptyLine . fmap (Pure . SplitDelete) <$> lines, both range (rangeAt $ snd previous))
Replace _ _ -> (zipWithDefaults makeRow (pure mempty) $ fmap (fmap (Pure . SplitReplace)) <$> lines, ranges)
Replace _ _ -> (zipWithDefaults makeRow (pure mempty) $ fmap (fmap (Pure . constructor patch)) <$> lines, ranges)
where (lines, ranges) = transpose $ maybe . (,) [] . rangeAt <$> previous <*> (splitAbstractedTerm copoint unwrap (:<) <$> sources) <*> unPatch patch
constructor (Replace _ _) = SplitReplace
constructor (Insert _) = SplitInsert
constructor (Delete _) = SplitDelete
-- | Split an `inTerm` (abstracted by two destructors) up into one `outTerm` (abstracted by a constructor) per line in `Source`.
splitAbstractedTerm :: (inTerm -> Info) -> (inTerm -> Syntax leaf inTerm) -> (Info -> Syntax leaf outTerm -> outTerm) -> Source Char -> inTerm -> ([Line outTerm], Range)