Handle edge cases involving consecutive "zero or" modifiers

This commit is contained in:
Samuel Moelius 2023-05-20 11:44:56 -04:00 committed by Amaan Qureshi
parent d9d4116105
commit a07cdb59f3
No known key found for this signature in database
GPG key ID: E67890ADC4227273

View file

@ -2597,8 +2597,11 @@ static TSQueryError ts_query__parse_pattern(
repeat_step.alternative_is_immediate = true;
array_push(&self->steps, repeat_step);
// Stop when `step->alternative_index` is `NONE` or it points to
// `repeat_step` or beyond. Note that having just been pushed,
// `repeat_step` occupies slot `self->steps.size - 1`.
QueryStep *step = &self->steps.contents[starting_step_index];
while (step->alternative_index != NONE) {
while (step->alternative_index != NONE && step->alternative_index < self->steps.size - 1) {
step = &self->steps.contents[step->alternative_index];
}
step->alternative_index = self->steps.size;
@ -2612,7 +2615,7 @@ static TSQueryError ts_query__parse_pattern(
stream_skip_whitespace(stream);
QueryStep *step = &self->steps.contents[starting_step_index];
while (step->alternative_index != NONE) {
while (step->alternative_index != NONE && step->alternative_index < self->steps.size) {
step = &self->steps.contents[step->alternative_index];
}
step->alternative_index = self->steps.size;