gostui-setup #1
@@ -17,8 +17,8 @@ fn main() {
|
||||
eprintln!();
|
||||
}
|
||||
|
||||
let options: Vec<(String, bool)> = nix::collect_nix_options_with_path(&ast.syntax(), "");
|
||||
for (path, value) in options {
|
||||
println!("{} = {};", path, value);
|
||||
let options: Vec<(String, String, bool)> = nix::collect_nix_options(&ast.syntax());
|
||||
for (category, path, value) in options {
|
||||
println!("{}: {} = {};", category, path, value);
|
||||
}
|
||||
}
|
||||
|
||||
52
src/nix.rs
52
src/nix.rs
@@ -1,12 +1,36 @@
|
||||
use rnix::{NodeOrToken, SyntaxKind, SyntaxNode};
|
||||
use rnix::{NodeOrToken, SyntaxKind, SyntaxNode, SyntaxToken};
|
||||
|
||||
pub fn collect_nix_options_with_path(node: &SyntaxNode, current_path: &str) -> Vec<(String, bool)> {
|
||||
let mut result: Vec<(String, bool)> = Vec::new();
|
||||
pub fn collect_nix_options(node: &SyntaxNode) -> Vec<(String, String, bool)> {
|
||||
collect_nix_options_with_path(node, "", "")
|
||||
}
|
||||
|
||||
for child in node.children_with_tokens() {
|
||||
if let NodeOrToken::Node(child_node) = child {
|
||||
match child_node.kind() {
|
||||
SyntaxKind::NODE_ATTRPATH_VALUE => {
|
||||
fn collect_nix_options_with_path(
|
||||
node: &SyntaxNode,
|
||||
current_path: &str,
|
||||
current_category: &str,
|
||||
) -> Vec<(String, String, bool)> {
|
||||
let mut result: Vec<(String, String, bool)> = Vec::new();
|
||||
let mut category: String = current_category.to_string();
|
||||
|
||||
let children: Vec<NodeOrToken<SyntaxNode, SyntaxToken>> = node.children_with_tokens().collect();
|
||||
|
||||
for i in 0..children.len() {
|
||||
match &children[i] {
|
||||
NodeOrToken::Token(token) if token.kind() == SyntaxKind::TOKEN_COMMENT => {
|
||||
let text: &str = token.text();
|
||||
if text.starts_with("/*") && text.ends_with("*/") {
|
||||
let content: String = text
|
||||
.trim_start_matches("/*")
|
||||
.trim_end_matches("*/")
|
||||
.trim()
|
||||
.to_string();
|
||||
category = content;
|
||||
}
|
||||
}
|
||||
|
||||
NodeOrToken::Node(child_node)
|
||||
if child_node.kind() == SyntaxKind::NODE_ATTRPATH_VALUE =>
|
||||
{
|
||||
let mut attr_path: String = String::new();
|
||||
let mut value_node: Option<SyntaxNode> = None;
|
||||
|
||||
@@ -32,6 +56,7 @@ pub fn collect_nix_options_with_path(node: &SyntaxNode, current_path: &str) -> V
|
||||
result.extend(collect_nix_options_with_path(
|
||||
&grand_node,
|
||||
&new_path,
|
||||
&category,
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
@@ -53,14 +78,19 @@ pub fn collect_nix_options_with_path(node: &SyntaxNode, current_path: &str) -> V
|
||||
bool_value = true;
|
||||
}
|
||||
|
||||
result.push((full_path, bool_value));
|
||||
result.push((category.clone(), full_path, bool_value));
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
result.extend(collect_nix_options_with_path(&child_node, current_path));
|
||||
}
|
||||
NodeOrToken::Node(child_node) => {
|
||||
result.extend(collect_nix_options_with_path(
|
||||
child_node,
|
||||
current_path,
|
||||
&category,
|
||||
));
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user