Add ts_query_disable_capture API
This commit is contained in:
parent
4c17af3ecd
commit
f490befcde
4 changed files with 46 additions and 2 deletions
|
|
@ -655,6 +655,16 @@ extern "C" {
|
|||
length: *mut u32,
|
||||
) -> *const ::std::os::raw::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Disable a certain capture within a query. This prevents the capture"]
|
||||
#[doc = " from being returned in matches, and also avoids any resource usage"]
|
||||
#[doc = " associated with recording the capture."]
|
||||
pub fn ts_query_disable_capture(
|
||||
arg1: *mut TSQuery,
|
||||
arg2: *const ::std::os::raw::c_char,
|
||||
arg3: u32,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Create a new cursor for executing a given query."]
|
||||
#[doc = ""]
|
||||
|
|
|
|||
|
|
@ -1202,6 +1202,16 @@ impl Query {
|
|||
&self.property_settings[index]
|
||||
}
|
||||
|
||||
pub fn disable_capture(&mut self, name: &str) {
|
||||
unsafe {
|
||||
ffi::ts_query_disable_capture(
|
||||
self.ptr.as_ptr(),
|
||||
name.as_bytes().as_ptr() as *const c_char,
|
||||
name.len() as u32,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_property(
|
||||
function_name: &str,
|
||||
capture_names: &[String],
|
||||
|
|
|
|||
|
|
@ -716,6 +716,13 @@ const char *ts_query_string_value_for_id(
|
|||
uint32_t *length
|
||||
);
|
||||
|
||||
/**
|
||||
* Disable a certain capture within a query. This prevents the capture
|
||||
* from being returned in matches, and also avoids any resource usage
|
||||
* associated with recording the capture.
|
||||
*/
|
||||
void ts_query_disable_capture(TSQuery *, const char *, uint32_t);
|
||||
|
||||
/**
|
||||
* Create a new cursor for executing a given query.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -889,6 +889,23 @@ uint32_t ts_query_start_byte_for_pattern(
|
|||
return self->start_bytes_by_pattern.contents[pattern_index];
|
||||
}
|
||||
|
||||
void ts_query_disable_capture(
|
||||
TSQuery *self,
|
||||
const char *name,
|
||||
uint32_t length
|
||||
) {
|
||||
int id = symbol_table_id_for_name(&self->captures, name, length);
|
||||
if (id != -1) {
|
||||
for (unsigned i = 0; i < self->steps.size; i++) {
|
||||
QueryStep *step = &self->steps.contents[i];
|
||||
if (step->capture_id == id) {
|
||||
step->capture_id = NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
ts_query__finalize_steps(self);
|
||||
}
|
||||
|
||||
/***************
|
||||
* QueryCursor
|
||||
***************/
|
||||
|
|
@ -1020,7 +1037,7 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
|
|||
} else if (ts_tree_cursor_goto_parent(&self->cursor)) {
|
||||
self->depth--;
|
||||
} else {
|
||||
return false;
|
||||
return self->finished_states.size > 0;
|
||||
}
|
||||
} else {
|
||||
bool can_have_later_siblings;
|
||||
|
|
@ -1214,7 +1231,7 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) {
|
|||
next_state->step_index++;
|
||||
QueryStep *next_step = step + 1;
|
||||
if (next_step->depth == PATTERN_DONE_MARKER) {
|
||||
LOG("finish pattern %u\n", next_state->pattern_index);
|
||||
LOG(" finish pattern %u\n", next_state->pattern_index);
|
||||
|
||||
next_state->id = self->next_state_id++;
|
||||
array_push(&self->finished_states, *next_state);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue