1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

Tacit definition of unpackLinesAndRanges.

This commit is contained in:
Rob Rix 2016-03-02 18:03:35 -05:00
parent 5cee42e6b2
commit 1dee480afd

View File

@ -3,6 +3,7 @@ module Alignment where
import Category
import Control.Comonad.Cofree
import Control.Monad.Free
import Data.Bifunctor
import Data.Either
import Data.Foldable (foldl')
import Data.Functor.Both
@ -51,7 +52,7 @@ splitPatchByLines patch previous sources = case patch of
Replace leftTerm rightTerm -> (zipWithDefaults makeRow (pure mempty) $ fmap (fmap (Pure . SplitReplace)) <$> lines, ranges)
where (lines, ranges) = unpackLinesAndRanges $ splitTermByLines <$> both leftTerm rightTerm <*> sources
unpackLinesAndRanges :: Both ([Line (Term leaf Info)], Range) -> (Both [Line (Term leaf Info)], Both Range)
unpackLinesAndRanges (Both ((leftLines, leftRange), (rightLines, rightRange))) = (Both (leftLines, rightLines), Both (leftRange, rightRange))
unpackLinesAndRanges = uncurry (uncurry bimap) . first (bimap both both) . runBoth
-- | Takes a term and a source and returns a list of lines and their range within source.
splitTermByLines :: Term leaf Info -> Source Char -> ([Line (Term leaf Info)], Range)