summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pipeline.rs34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/pipeline.rs b/src/pipeline.rs
index cba046f..cce3e31 100644
--- a/src/pipeline.rs
+++ b/src/pipeline.rs
@@ -78,12 +78,33 @@ impl Root {
}
}
+// address nodes by their role relative to their parent
+enum NixSyntaxRole {
+ Argument,
+ Function,
+ Attribute,
+ // TODO
+}
+
+impl NixSyntaxRole {
+ fn from_str(from: &str) -> Option<NixSyntaxRole> {
+ use NixSyntaxRole::*;
+ Some(match from {
+ "Argument" => Argument,
+ "Function" => Function,
+ "Attribute" => Attribute,
+ _ => return None
+ })
+ }
+}
+
enum Op {
Down,
DownRecursive,
Up,
UpRecursive,
NixSyntaxNode(rnix::SyntaxKind),
+ NixSyntaxRole(NixSyntaxRole),
Named(String)
}
@@ -100,7 +121,11 @@ impl Atom {
"Inherit" => Op::NixSyntaxNode(rnix::SyntaxKind::NODE_INHERIT),
"String" => Op::NixSyntaxNode(rnix::SyntaxKind::NODE_STRING),
// TODO other syntax nodes
- name => Op::Named(name.to_owned()),
+ name => if let Some(role) = NixSyntaxRole::from_str(name) {
+ Op::NixSyntaxRole(role)
+ } else {
+ Op::Named(name.to_owned())
+ },
};
Some(op)
}
@@ -129,6 +154,13 @@ impl Atom {
Some(Op::UpRecursive) => Box::new(acc.map(|s| s.ancestors()).flatten()),
// TODO: how to select roles relative to previous node?
Some(Op::NixSyntaxNode(kind)) => Box::new(acc.filter(move |s| s.kind() == kind)),
+ Some(Op::NixSyntaxRole(role)) => {use NixSyntaxRole::*; match role {
+ Argument => Box::new(acc.filter_map(move |s| match_ast! { match s {
+ ast::Apply(value) => value.argument().map(|s| s.syntax().to_owned()),
+ _ => None
+ }})),
+ _ => todo!()
+ }}
Some(Op::Named(name)) =>
Box::new(acc
.filter(move |node| match_ast! { match node {