mirror of
https://github.com/github/semantic.git
synced 2024-12-22 22:31:36 +03:00
Extract alignSyntax to the top level.
This commit is contained in:
parent
5ffd45ebe5
commit
013bf6e1c0
@ -124,15 +124,16 @@ alignPatch _ _ = []
|
|||||||
-- alignTerm sources infos syntax = (\ (source, info) -> Free . Annotated info <$> alignSyntax source (characterRange info) syntax) <$> Join (pairWithThese sources (runJoin infos))
|
-- 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 :: Both (Source Char) -> Diff leaf Info -> AlignedDiff leaf
|
||||||
alignDiff sources diff = iter alignSyntax (alignPatch sources <$> diff)
|
alignDiff sources diff = iter (alignSyntax sources) (alignPatch sources <$> diff)
|
||||||
where alignSyntax :: Annotated leaf (Both Info) (AlignedDiff leaf) -> AlignedDiff leaf
|
|
||||||
alignSyntax (Annotated infos syntax) = case syntax of
|
alignSyntax :: Both (Source Char) -> Annotated leaf (Both Info) (AlignedDiff leaf) -> AlignedDiff leaf
|
||||||
Leaf s -> modifyJoin (runBothWith bimap (((Free . (`Annotated` Leaf s)) .) . setCharacterRange <$> infos)) <$> sequenceL lineRanges
|
alignSyntax sources (Annotated infos syntax) = case syntax of
|
||||||
Indexed children -> wrapInBranch Indexed <$> groupChildrenByLine lineRanges children
|
Leaf s -> modifyJoin (runBothWith bimap (((Free . (`Annotated` Leaf s)) .) . setCharacterRange <$> infos)) <$> sequenceL lineRanges
|
||||||
Fixed children -> wrapInBranch Fixed <$> groupChildrenByLine lineRanges children
|
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))
|
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 :: Join These [Range] -> [AlignedDiff leaf] -> [Join These (Range, [SplitDiff leaf Info])]
|
||||||
groupChildrenByLine ranges children | (nextRanges, nextChildren, lines) <- group2 ranges children
|
groupChildrenByLine ranges children | (nextRanges, nextChildren, lines) <- group2 ranges children
|
||||||
|
Loading…
Reference in New Issue
Block a user