Replies: 1 comment 1 reply
-
Did you end up finding something? I'm facing the same issue right now. I think I'll have to handle that in bindings, since it looks like there's a way to walk the parents of all nodes programmatically, so a filter can be implemented there. I'm currently doing fn is_within_mod_item(node: Node) -> bool {
let mut walk = node;
loop {
if walk.kind() == "mod_item" {
break true;
}
if let Some(parent) = walk.parent() {
walk = parent;
continue;
}
break false;
}
} you can change EDIT: and a bigger version, with maximum recursion limit, and access to the source code to log things: fn is_within_mod_item(node: Node, max_parent: Option<Node>, source: &str) -> bool {
let mut walk = node;
loop {
if walk.kind() == "mod_item" {
eprintln!(
"Node was inside a mod.\nNode:{}\nMax Parent:{}\n",
node.utf8_text(source.as_bytes())
.map(ToString::to_string)
.unwrap(),
if let Some(node) = max_parent {
node.utf8_text(source.as_bytes())
.map(ToString::to_string)
.unwrap()
} else {
source.to_string()
}
);
break true;
}
if let Some(parent) = walk.parent() {
if max_parent.map_or(false, |max_parent| parent.id() == max_parent.id()) {
break false;
}
walk = parent;
continue;
}
break false;
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am building a spell/grammar checker for multiple languages. I use tree-sitter to extract strings/comments/text. For latex, a markup language, I do not want to match all text nodes only those that are not part of a mathematical formula.
Can I capture any
text
nodes that is not the child of ainline_formula
parent? See this example:Is there a way to do this in the query? I can not seem to find a negate parent option.
Beta Was this translation helpful? Give feedback.
All reactions