Skip to content

Commit

Permalink
experimenting with handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Oct 28, 2023
1 parent 3941004 commit d72cde5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
61 changes: 38 additions & 23 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
fn main() {
let base = r#"
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
int y = 4;
int j = 0;
}
}
"#;
// let base = r#"
// public class Main {
// public static void main(String[] args) {
// System.out.println("Hello, world!");
// int y = 4;
// int j = 0;
// }
// }
// "#;
// let left = r#"
// public class Main {
// public static void main(String[] args) {
// int x = 0;
// System.out.println("Hello, João!");
// int y = 3;
// int j = 0;
// }
// }
// "#;
// let right = r#"
// public class Main {
// public static void main(String[] args) {
// System.out.println("Hello, Paulo!");
// int y = 3;
// }
// }
// "#;

let base = r##"
public static interface IRepository {
}
"##;
let left = r#"
public class Main {
public static void main(String[] args) {
int x = 0;
System.out.println("Hello, João!");
int y = 3;
int j = 0;
}
}
public static interface IRepository {
void create(Pessoa pessoa);
}
"#;
let right = r#"
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Paulo!");
int y = 3;
}
}
public static interface IRepository {
void delete(Pessoa pessoa);
}
"#;

let parser_configuration = parsing::ParserConfiguration::from_language(model::Language::Java);
Expand Down
22 changes: 21 additions & 1 deletion matching/src/ordered_tree_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,27 @@ fn ordered_tree_matching_helper<'a>(
children: children_right,
},
) => {
let root_matching: usize = (kind_left == kind_right).into();
let root_matching: usize = match (kind_left == kind_right) {

Check warning on line 44 in matching/src/ordered_tree_matching.rs

View workflow job for this annotation

GitHub Actions / build

unnecessary parentheses around `match` scrutinee expression

Check warning on line 44 in matching/src/ordered_tree_matching.rs

View workflow job for this annotation

GitHub Actions / test

unnecessary parentheses around `match` scrutinee expression
false => 0,
true => {
let left_identifier = children_left.iter().find(|node| match node {
CSTNode::Terminal { kind, .. } => kind == &"identifier",
_ => false
});
let right_identifier = children_right.iter().find(|node| match node {
CSTNode::Terminal { kind, .. } => kind == &"identifier",
_ => false
});

match (left_identifier, right_identifier) {
(Some(CSTNode::Terminal { value: value_left, .. }), Some(CSTNode::Terminal { value: value_right, .. })) => {
println!("{} {}", value_left, value_right);
if (value_left == value_right) { 1 } else { 0 }

Check warning on line 59 in matching/src/ordered_tree_matching.rs

View workflow job for this annotation

GitHub Actions / build

unnecessary parentheses around `if` condition

Check warning on line 59 in matching/src/ordered_tree_matching.rs

View workflow job for this annotation

GitHub Actions / test

unnecessary parentheses around `if` condition
}
(_,_) => 0
}
}
};

let m = children_left.len();
let n = children_right.len();
Expand Down

0 comments on commit d72cde5

Please sign in to comment.