1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 00:42:33 +03:00

Move Split & Unified into the library.

This commit is contained in:
Rob Rix 2015-12-03 11:37:18 -05:00
parent 51db79e961
commit bbcb3be6fc
3 changed files with 39 additions and 1 deletions

View File

@ -23,6 +23,8 @@ library
, Categorizable
, Term
, Range
, Split
, Unified
build-depends: base >= 4.8 && < 5
, containers
, free
@ -43,7 +45,6 @@ executable semantic-diff-exe
, bytestring
, optparse-applicative
default-language: Haskell2010
other-modules: Unified, Split
extra-libraries: bridge
extra-lib-dirs: prototype/External/tree-sitter/out/Release, prototype/External/tree-sitter-c, .

View File

@ -25,6 +25,8 @@ split _ _ _ = return mempty
data Row = Row (Maybe HTML) (Maybe HTML)
-- data Line = Line
diffToRows :: Diff a Info -> String -> String -> ([Row], Range, Range)
diffToRows (Free (Annotated (Info leftRange _ leftCategories, Info rightRange _ rightCategories) syntax)) before after = (annotationAndSyntaxToRows leftRange leftCategories rightRange rightCategories syntax before after, leftRange, rightRange)
@ -45,6 +47,41 @@ annotationAndSyntaxToRows left leftCategories right rightCategories (Indexed i)
leftElements = Text <$> lines (substring (Range previousLeft $ start left) before)
rightElements = Text <$> lines (substring (Range previousRight $ start right) before)
{-
in: ([ Line "a.b" ], [ Line "a.b" ]) ([ Line "(c, d, [", Line " e,", Line " f", Line "])" ], [ Line "(c, d, [", Line " ", Line " e,", Line " ", Line " f", Line "])" ])
out: ([ Line "a.b(c, d, [", Line " e,", Line " f", Line "])" ], [ Line "a.b(c, d, [", Line " ", Line " e,", Line " ", Line " f", Line "])" ])
a.b(c, d, [
e,
f
])
a.b(c, d, [
e,
f
])
[
123, false,
{ "x": null
}
]
[
123,
false,
{ "x": null
}
]
-}
zipMaybe :: [a] -> [b] -> [(Maybe a, Maybe b)]
zipMaybe la lb = take len $ zip la' lb'
where