Getting matched Node (without captures) from queries #898
-
let query = Query::new(language, &query).unwrap();
let root = tree.root_node();
println!("Matches:");
let mut query_cursor = QueryCursor::new();
for match_ in query_cursor.matches(&query, root, to_callback(&file_contents)) {
println!(" {:?} (pattern_index={})", match_, match_.pattern_index);
for capture in match_.captures {
let node = capture.node;
println!(" {:?} (index={})", node, capture.index);
}
} If I run the code above using Rust parser and a query like As far as I can see from the documentation, C API also doesn't support this. Is this difficult to do? One idea is to add some dummy capture for every query string, like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There isn't always one root node to a pattern; you can write a pattern like this: (
(comment)+
(function_definition)
)
I think that in most cases this will work. Even if the user writes a top-level capture, it is still valid to have multiple captures like (return_statement) @foo @bar There will just be two named captures for the same node. |
Beta Was this translation helpful? Give feedback.
There isn't always one root node to a pattern; you can write a pattern like this:
I think that in most cases this will work. Even if the user writes a top-level capture, it is still valid to have multiple captures like
(return_statement) @foo @bar
There will just be two named captures for the same node.