fix(lib): propagate last_child status to pattern alternatives in queries
Previously, when a pattern was marked as the last child in a query, its alternatives weren't marked similarly, causing incorrect matching behavior. Now, the `last_child` status is properly propagated through all alternatives.
This commit is contained in:
parent
f8e77aa99d
commit
a7e6d01144
2 changed files with 92 additions and 1 deletions
|
|
@ -2491,7 +2491,20 @@ static TSQueryError ts_query__parse_pattern(
|
|||
capture_quantifiers_delete(&child_capture_quantifiers);
|
||||
return TSQueryErrorSyntax;
|
||||
}
|
||||
self->steps.contents[last_child_step_index].is_last_child = true;
|
||||
// Mark this step *and* its alternatives as the last child of the parent.
|
||||
QueryStep *last_child_step = &self->steps.contents[last_child_step_index];
|
||||
last_child_step->is_last_child = true;
|
||||
if (last_child_step->alternative_index != NONE) {
|
||||
QueryStep *alternative_step = &self->steps.contents[last_child_step->alternative_index];
|
||||
alternative_step->is_last_child = true;
|
||||
while (
|
||||
alternative_step->alternative_index != NONE &&
|
||||
alternative_step->alternative_index < self->steps.size
|
||||
) {
|
||||
alternative_step = &self->steps.contents[alternative_step->alternative_index];
|
||||
alternative_step->is_last_child = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (negated_field_count) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue