diff options
author | Akshay <[email protected]> | 2022-08-02 12:27:04 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2022-08-02 12:27:04 +0100 |
commit | efd96e8df6805a45aaf5822141dee11c642b51ae (patch) | |
tree | 56cca3a780dd0753e21eb5e0dbda585ce6ff7f7b /src/main.rs |
init
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..77c7584 --- /dev/null +++ b/src/main.rs | |||
@@ -0,0 +1,43 @@ | |||
1 | // extern | ||
2 | use itertools::Itertools; | ||
3 | use rayon::prelude::*; | ||
4 | use similarity::{ProgramFile, Similarity}; | ||
5 | use tree_sitter::Parser; | ||
6 | |||
7 | fn parser() -> Parser { | ||
8 | let mut parser = Parser::new(); | ||
9 | parser | ||
10 | .set_language(tree_sitter_javascript::language()) | ||
11 | .unwrap(); | ||
12 | parser | ||
13 | } | ||
14 | |||
15 | fn main() { | ||
16 | let args = std::env::args().skip(1).collect::<Vec<_>>(); | ||
17 | |||
18 | // read and parse files from disk | ||
19 | let (files, errors): (Vec<_>, Vec<_>) = args | ||
20 | .par_iter() | ||
21 | .map(|arg| ProgramFile::new(arg, &mut parser())) | ||
22 | .partition(Result::is_ok); | ||
23 | |||
24 | // dump errors if any | ||
25 | errors.into_iter().map(Result::unwrap_err).for_each(|err| { | ||
26 | eprintln!("{}", err); | ||
27 | }); | ||
28 | |||
29 | let files: Vec<_> = files.into_iter().map(Result::unwrap).collect(); | ||
30 | |||
31 | // compare every pair of files for similarity | ||
32 | (0..files.len()) | ||
33 | .combinations(2) | ||
34 | .map(|item| (item[0], item[1])) | ||
35 | .par_bridge() | ||
36 | .for_each(|(one, two)| { | ||
37 | let one = &files[one]; | ||
38 | let two = &files[two]; | ||
39 | if one.is_similar(&two, |n| !n.is_extra()) && one.path != two.path { | ||
40 | println!("{} {}", one.path.display(), two.path.display()); | ||
41 | } | ||
42 | }); | ||
43 | } | ||