aboutsummaryrefslogtreecommitdiff
path: root/lib/src/make.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/make.rs')
-rw-r--r--lib/src/make.rs15
1 files changed, 13 insertions, 2 deletions
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 @@
1use rnix::{SyntaxNode, types::{TypedNode, self}}; 1use std::iter::IntoIterator;
2
3use rnix::{SyntaxNode, types::{TypedNode, self, TokenWrapper}};
2 4
3fn ast_from_text<N: TypedNode>(text: &str) -> N { 5fn ast_from_text<N: TypedNode>(text: &str) -> N {
4 let parse = rnix::parse(text); 6 let parse = rnix::parse(text);
5 let node = match parse.node().descendants().find_map(N::cast) { 7 let node = match parse.node().descendants().find_map(N::cast) {
6 Some(it) => it, 8 Some(it) => it,
7 None => { 9 None => {
8 panic!("Failed to make ast node `{}` from text {}", std::any::type_name::<N>(), text) 10 panic!("Failed to make ast node `{}` from text `{}`", std::any::type_name::<N>(), text)
9 } 11 }
10 }; 12 };
11 node 13 node
@@ -18,3 +20,12 @@ pub fn parenthesize(node: &SyntaxNode) -> types::Paren {
18pub fn unary_not(node: &SyntaxNode) -> types::UnaryOp { 20pub fn unary_not(node: &SyntaxNode) -> types::UnaryOp {
19 ast_from_text(&format!("!{}", node)) 21 ast_from_text(&format!("!{}", node))
20} 22}
23
24pub fn inherit_stmt<'a>(nodes: impl IntoIterator<Item = &'a types::Ident>) -> types::Inherit {
25 let inherited_idents = nodes
26 .into_iter()
27 .map(|i| i.as_str().to_owned())
28 .collect::<Vec<_>>()
29 .join(" ");
30 ast_from_text(&format!("{{ inherit {}; }}", inherited_idents))
31}