feat(lib): add ts_query_end_byte_for_pattern

This commit is contained in:
Amaan Qureshi 2024-07-04 20:51:27 -04:00
parent 3095fbe07b
commit 25c7189180
5 changed files with 52 additions and 10 deletions

View file

@ -146,6 +146,7 @@ typedef struct {
Slice steps;
Slice predicate_steps;
uint32_t start_byte;
uint32_t end_byte;
bool is_non_local;
} QueryPattern;
@ -2715,6 +2716,7 @@ TSQuery *ts_query_new(
QueryPattern *pattern = array_back(&self->patterns);
pattern->steps.length = self->steps.size - start_step_index;
pattern->predicate_steps.length = self->predicate_steps.size - start_predicate_step_index;
pattern->end_byte = stream_offset(&stream);
// If any pattern could not be parsed, then report the error information
// and terminate.
@ -2873,6 +2875,13 @@ uint32_t ts_query_start_byte_for_pattern(
return self->patterns.contents[pattern_index].start_byte;
}
uint32_t ts_query_end_byte_for_pattern(
const TSQuery *self,
uint32_t pattern_index
) {
return self->patterns.contents[pattern_index].end_byte;
}
bool ts_query_is_pattern_rooted(
const TSQuery *self,
uint32_t pattern_index