1 unstable release
0.0.0 | Dec 23, 2023 |
---|
#15 in #lcs
5KB
54 lines
syn-merge
Merge syn
structures by adding cfg
s.
Thoughts about diffing
Should operate directly on Rust source code (not on some custom AST).
Able to operate on multiple files (in contrast to most diffing out there).
Longest common subsequence algorithm?
How do we handle ties? Some kind of weighting?
Basically:
let contents = vec![...];
let files = contents.iter().map(syn::parse_file).flatten()?;
let merged = syn_merge::merge(files)?;
file.write(prettyplease::unparse(merged))?;
Literature and prior work
The similar
crate implements various
diffing algorithms.
difftastic/src/diff
also has a few algorithms.
The wu-diff
crate, which implements
Wu, Sun; Manber, Udi; Myers, Gene (1989). "An O(NP) Sequence Comparison Algorithm".
However, there is very little research on diffing between multiple files.
Khanna, Sanjeev & Kunal, Keshav & Pierce, Benjamin. (2007). A Formal Investigation of Diff3.
"Generalized Longest Common Subsequence / LCS"
lib.rs
:
Diff an arbitary number of inputs
Fundamentally, it works by constructing an input matrix like:
Key | Data |
---|---|
0 | aab |
1 | baa |
2 | bc |
3 | abc |
And producing an output matrix like (may vary depending on algorithm details):
Char | Appears In |
---|---|
a | 0, 3 |
a | 0 |
b | 0, 1, 2, 3 |
a | 1 |
a | 1 |
c | 2, 3 |
Note how this can encode the same information as a diff between just two elements:
Key | Data |
---|---|
old | aabc |
new | baac |
Char | Appears In |
---|---|
b | new |
a | old, new |
a | old, new |
b | old |
c | old, new |
+b
a
a
-b
c
Dependencies
~185KB