aboutsummaryrefslogtreecommitdiff
path: root/lib/src/make.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-09-21 12:11:24 +0100
committerAkshay <[email protected]>2021-09-21 12:11:24 +0100
commit40867728c023a9f95f346671b51be68002cc7552 (patch)
treee856327b0d42d9a4740c460a5efb633f8a73f3d9 /lib/src/make.rs
parentc91c2ae1398e4f567ee5e4c50a1da35a9b65919b (diff)
add suggestion to bool_comparison
Diffstat (limited to 'lib/src/make.rs')
-rw-r--r--lib/src/make.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/src/make.rs b/lib/src/make.rs
new file mode 100644
index 0000000..0b21105
--- /dev/null
+++ b/lib/src/make.rs
@@ -0,0 +1,20 @@
1use rnix::{SyntaxNode, types::{TypedNode, self}};
2
3fn ast_from_text<N: TypedNode>(text: &str) -> N {
4 let parse = rnix::parse(text);
5 let node = match parse.node().descendants().find_map(N::cast) {
6 Some(it) => it,
7 None => {
8 panic!("Failed to make ast node `{}` from text {}", std::any::type_name::<N>(), text)
9 }
10 };
11 node
12}
13
14pub fn parenthesize(node: &SyntaxNode) -> types::Paren {
15 ast_from_text(&format!("({})", node))
16}
17
18pub fn unary_not(node: &SyntaxNode) -> types::UnaryOp {
19 ast_from_text(&format!("!{}", node))
20}