From 90d719a90faa5bbef5c95a26a864021befdf82ed Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 11 Mar 2021 21:22:41 -0800 Subject: [PATCH] Allow finding all nodes and nodes containing a string When using the `-f` option in `rust-code-analysis-cli` to find nodes, the current behavior is to return all found nodes if the passed filter string is not one of `call|comment|error|string|function|`. I found it useful to be able to find nodes that contained a certain string (e.g. `expr`) so I added this functionality. Because in testing I found that an empty `-f` never creates the "accept all" filter, I added a keyword `"all"` to enable this behavior (also quite useful). The filters now accept `all|call|comment|error|string|function||`. --- src/parser.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 5bb3f7c07..fccd8b741 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -121,6 +121,7 @@ impl Pars for f in filters.iter() { let f = f.as_str(); match f { + "all" => res.push(Box::new(|_: &Node| -> bool { true })), "call" => res.push(Box::new(T::is_call)), "comment" => res.push(Box::new(T::is_comment)), "error" => res.push(Box::new(T::is_error)), @@ -131,6 +132,11 @@ impl Pars res.push(Box::new(move |node: &Node| -> bool { node.object().kind_id() == n })); + } else { + let f = f.to_owned(); + res.push(Box::new(move |node: &Node| -> bool { + node.object().kind().contains(&f) + })); } } }