From 013bf6e1c0b0c39bcee8b65da1a2ef585e0cbe4b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 4 Apr 2016 15:49:22 -0400 Subject: [PATCH] Extract alignSyntax to the top level. --- src/Alignment.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Alignment.hs b/src/Alignment.hs index 10531ab80..e75cbbae0 100644 --- a/src/Alignment.hs +++ b/src/Alignment.hs @@ -124,15 +124,16 @@ alignPatch _ _ = [] -- alignTerm sources infos syntax = (\ (source, info) -> Free . Annotated info <$> alignSyntax source (characterRange info) syntax) <$> Join (pairWithThese sources (runJoin infos)) alignDiff :: Both (Source Char) -> Diff leaf Info -> AlignedDiff leaf -alignDiff sources diff = iter alignSyntax (alignPatch sources <$> diff) - where alignSyntax :: Annotated leaf (Both Info) (AlignedDiff leaf) -> AlignedDiff leaf - alignSyntax (Annotated infos syntax) = case syntax of - Leaf s -> modifyJoin (runBothWith bimap (((Free . (`Annotated` Leaf s)) .) . setCharacterRange <$> infos)) <$> sequenceL lineRanges - Indexed children -> wrapInBranch Indexed <$> groupChildrenByLine lineRanges children - Fixed children -> wrapInBranch Fixed <$> groupChildrenByLine lineRanges children - _ -> [] - where lineRanges = runBothWith ((Join .) . These) (actualLineRanges <$> (characterRange <$> infos) <*> sources) - wrapInBranch constructor = modifyJoin (runBothWith bimap ((\ info (range, children) -> Free (Annotated (setCharacterRange info range) (constructor children))) <$> infos)) +alignDiff sources diff = iter (alignSyntax sources) (alignPatch sources <$> diff) + +alignSyntax :: Both (Source Char) -> Annotated leaf (Both Info) (AlignedDiff leaf) -> AlignedDiff leaf +alignSyntax sources (Annotated infos syntax) = case syntax of + Leaf s -> modifyJoin (runBothWith bimap (((Free . (`Annotated` Leaf s)) .) . setCharacterRange <$> infos)) <$> sequenceL lineRanges + Indexed children -> wrapInBranch Indexed <$> groupChildrenByLine lineRanges children + Fixed children -> wrapInBranch Fixed <$> groupChildrenByLine lineRanges children + _ -> [] + where lineRanges = runBothWith ((Join .) . These) (actualLineRanges <$> (characterRange <$> infos) <*> sources) + wrapInBranch constructor = modifyJoin (runBothWith bimap ((\ info (range, children) -> Free (Annotated (setCharacterRange info range) (constructor children))) <$> infos)) groupChildrenByLine :: Join These [Range] -> [AlignedDiff leaf] -> [Join These (Range, [SplitDiff leaf Info])] groupChildrenByLine ranges children | (nextRanges, nextChildren, lines) <- group2 ranges children