Fix match return order fom ts_query_cursor_next_match
This commit is contained in:
parent
1af85dc3f7
commit
2d1ca8bc9f
3 changed files with 21 additions and 16 deletions
|
|
@ -266,15 +266,15 @@ fn test_query_matches_with_nesting_and_no_fields() {
|
|||
"
|
||||
(array
|
||||
(array
|
||||
(identifier) @element-1
|
||||
(identifier) @element-2))
|
||||
(identifier) @x1
|
||||
(identifier) @x2))
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let source = "
|
||||
[[a]];
|
||||
[[c, d], [e, f, g]];
|
||||
[[c, d], [e, f, g, h]];
|
||||
[[h], [i]];
|
||||
";
|
||||
|
||||
|
|
@ -287,10 +287,13 @@ fn test_query_matches_with_nesting_and_no_fields() {
|
|||
assert_eq!(
|
||||
collect_matches(matches, &query, source),
|
||||
&[
|
||||
(0, vec![("element-1", "c"), ("element-2", "d")]),
|
||||
(0, vec![("element-1", "e"), ("element-2", "f")]),
|
||||
(0, vec![("element-1", "f"), ("element-2", "g")]),
|
||||
(0, vec![("element-1", "e"), ("element-2", "g")]),
|
||||
(0, vec![("x1", "c"), ("x2", "d")]),
|
||||
(0, vec![("x1", "e"), ("x2", "f")]),
|
||||
(0, vec![("x1", "e"), ("x2", "g")]),
|
||||
(0, vec![("x1", "f"), ("x2", "g")]),
|
||||
(0, vec![("x1", "e"), ("x2", "h")]),
|
||||
(0, vec![("x1", "f"), ("x2", "h")]),
|
||||
(0, vec![("x1", "g"), ("x2", "h")]),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ impl Parser {
|
|||
pub fn set_logger(&mut self, logger: Option<Logger>) {
|
||||
let prev_logger = unsafe { ffi::ts_parser_logger(self.0) };
|
||||
if !prev_logger.payload.is_null() {
|
||||
unsafe { Box::from_raw(prev_logger.payload as *mut Logger) };
|
||||
drop(unsafe { Box::from_raw(prev_logger.payload as *mut Logger) });
|
||||
}
|
||||
|
||||
let c_logger;
|
||||
|
|
|
|||
|
|
@ -843,6 +843,8 @@ TSQueryCursor *ts_query_cursor_new() {
|
|||
.start_point = {0, 0},
|
||||
.end_point = POINT_MAX,
|
||||
};
|
||||
array_reserve(&self->states, MAX_STATE_COUNT);
|
||||
array_reserve(&self->finished_states, MAX_STATE_COUNT);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
@ -897,7 +899,7 @@ void ts_query_cursor_set_point_range(
|
|||
|
||||
static QueryState *ts_query_cursor_copy_state(
|
||||
TSQueryCursor *self,
|
||||
QueryState *state
|
||||
const QueryState *state
|
||||
) {
|
||||
uint32_t new_list_id = capture_list_pool_acquire(&self->capture_list_pool);
|
||||
if (new_list_id == NONE) return NULL;
|
||||
|
|
@ -1147,14 +1149,13 @@ bool ts_query_cursor_next_match(
|
|||
TSQueryCursor *self,
|
||||
TSQueryMatch *match
|
||||
) {
|
||||
if (self->finished_states.size > 0) {
|
||||
QueryState state = array_pop(&self->finished_states);
|
||||
capture_list_pool_release(&self->capture_list_pool, state.capture_list_id);
|
||||
if (self->finished_states.size == 0) {
|
||||
if (!ts_query_cursor__advance(self)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ts_query_cursor__advance(self)) return false;
|
||||
|
||||
const QueryState *state = array_back(&self->finished_states);
|
||||
QueryState *state = &self->finished_states.contents[0];
|
||||
match->id = state->id;
|
||||
match->pattern_index = state->pattern_index;
|
||||
match->capture_count = state->capture_count;
|
||||
|
|
@ -1162,7 +1163,8 @@ bool ts_query_cursor_next_match(
|
|||
&self->capture_list_pool,
|
||||
state->capture_list_id
|
||||
);
|
||||
|
||||
capture_list_pool_release(&self->capture_list_pool, state->capture_list_id);
|
||||
array_erase(&self->finished_states, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue