1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00

Accumulate context between children.

This commit is contained in:
Rob Rix 2015-11-19 15:56:58 -08:00
parent b133e572c7
commit 6fa7204728

View File

@ -23,9 +23,8 @@ unified diff before after =
unifiedRange :: Range -> [(String, Maybe Range)] -> String -> String
unifiedRange range children source = out ++ substring Range { start = previous, end = end range } after where
(out, previous) = foldl accumulateContext ("", start range) children
accumulateContext (out, previous) (source, Just range) = (out ++ source, end range)
accumulateContext (out, previous) (source, _) = (out, previous)
accumulateContext (out, previous) (child, Just range) = (out ++ substring Range { start = previous, end = start range } source ++ child, end range)
accumulateContext (out, previous) (child, _) = (out ++ child, previous)
substring :: Range -> String -> String
substring range = take (end range) . drop (start range)