mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:36:22 -04:00
fix(query): take anchors between siblings into account for fallible step splitting
Problem: In queries matching a parent node with anchored children (siblings), the check for fallible steps only considers nodes with children, which results in no state split being made for anchored siblings (node1) . (node2). This prevents the query from matching beyond the first occurrence. Solution: Make the check for fallible steps consider also the case where the next step is at the same depth and must be matched immediately after.
This commit is contained in:
parent
cdae49be40
commit
1b110f62dd
|
|
@ -1593,6 +1593,38 @@ fn test_query_matches_with_leading_zero_or_more_repeated_leaf_nodes() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_matches_with_anchor_sibling_inside_parent() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("rust");
|
||||
|
||||
let query = Query::new(
|
||||
&language,
|
||||
"
|
||||
(source_file
|
||||
(line_comment)
|
||||
.
|
||||
(function_item
|
||||
name: (identifier) @name)
|
||||
)",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_query_matches(
|
||||
&language,
|
||||
&query,
|
||||
"
|
||||
// A
|
||||
fn a() {}
|
||||
|
||||
// B
|
||||
fn b() {}
|
||||
",
|
||||
&[(0, vec![("name", "a")]), (0, vec![("name", "b")])],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_trailing_optional_nodes() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
|
|
@ -3292,7 +3292,8 @@ bool ts_query__step_is_fallible(
|
|||
QueryStep *next_step = array_get(&self->steps, step_index + 1);
|
||||
return (
|
||||
next_step->depth != PATTERN_DONE_MARKER &&
|
||||
next_step->depth > step->depth &&
|
||||
(next_step->depth > step->depth ||
|
||||
(next_step->depth == step->depth && next_step->is_immediate)) &&
|
||||
(!next_step->parent_pattern_guaranteed || step->symbol == WILDCARD_SYMBOL)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue