-
-
Save wz1000/cf71f931893a441ca005c148c8ce1afd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mappingFromDiff :: BS.ByteString -> BS.ByteString -> PositionMapping | |
mappingFromDiff (BS.lines -> old) (BS.lines -> new) = PositionMapping (PositionDelta (lookupPos lnew old2new) (lookupPos lold new2old)) | |
where | |
diff = getDiff old new | |
(!old2new, !new2old) = go diff 0 0 | |
lnew = lines new | |
lold = lines old | |
lookupPos :: [(Int,Maybe Int)] -> Position -> PositionResult Position | |
lookupPos max xs (Position line col) = go 0 xs | |
where | |
go prev [] = PositionRange (Position (prev+1) 0) (Position max 0) | |
go prev ((a,b):xs) = _ | |
go [] _ _ = ([],[]) | |
go (Both _ _ : xs) lold lnew = bimap ((lold,Just lnew) :) ((lnew,Just lold) :) $ go xs (lold+1) (lnew+1) | |
go (First _ : xs) lold lnew = first ((lold,Nothing) :) $ go xs (lold+1) lnew | |
go (Second _ : xs) lold lnew = second ((lnew,Nothing) :) $ go xs lold (lnew+1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment