From c00900120d88c3d42666ed93716b821bd694e8d6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 2 Oct 2021 13:39:11 +0530 Subject: new lint: manual_inherit --- lib/src/make.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/src/make.rs') diff --git a/lib/src/make.rs b/lib/src/make.rs index 0b21105..facd247 100644 --- a/lib/src/make.rs +++ b/lib/src/make.rs @@ -1,11 +1,13 @@ -use rnix::{SyntaxNode, types::{TypedNode, self}}; +use std::iter::IntoIterator; + +use rnix::{SyntaxNode, types::{TypedNode, self, TokenWrapper}}; fn ast_from_text(text: &str) -> N { let parse = rnix::parse(text); let node = match parse.node().descendants().find_map(N::cast) { Some(it) => it, None => { - panic!("Failed to make ast node `{}` from text {}", std::any::type_name::(), text) + panic!("Failed to make ast node `{}` from text `{}`", std::any::type_name::(), text) } }; node @@ -18,3 +20,12 @@ pub fn parenthesize(node: &SyntaxNode) -> types::Paren { pub fn unary_not(node: &SyntaxNode) -> types::UnaryOp { ast_from_text(&format!("!{}", node)) } + +pub fn inherit_stmt<'a>(nodes: impl IntoIterator) -> types::Inherit { + let inherited_idents = nodes + .into_iter() + .map(|i| i.as_str().to_owned()) + .collect::>() + .join(" "); + ast_from_text(&format!("{{ inherit {}; }}", inherited_idents)) +} -- cgit v1.2.3