Tweak query interface
* Rename TSQueryContext -> TSQueryCursor * Remove the permanent association between the cursor and its query. The cursor can now be used again for a different query.
This commit is contained in:
parent
c8c75782e3
commit
c71de5bd81
9 changed files with 142 additions and 147 deletions
|
|
@ -26,7 +26,7 @@ pub struct TSQuery {
|
|||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSQueryContext {
|
||||
pub struct TSQueryCursor {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
pub const TSInputEncoding_TSInputEncodingUTF8: TSInputEncoding = 0;
|
||||
|
|
@ -604,56 +604,52 @@ extern "C" {
|
|||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Create a new context for executing a given query."]
|
||||
#[doc = " Create a new cursor for executing a given query."]
|
||||
#[doc = ""]
|
||||
#[doc = " The context stores the state that is needed to iteratively search"]
|
||||
#[doc = " for matches. To use the query context:"]
|
||||
#[doc = " 1. First call `ts_query_context_exec` to start running the query"]
|
||||
#[doc = " on a particular syntax node."]
|
||||
#[doc = " 2. Then repeatedly call `ts_query_context_next` to iterate over"]
|
||||
#[doc = " the matches."]
|
||||
#[doc = " 3. After each successful call to `ts_query_context_next`, you can call"]
|
||||
#[doc = " `ts_query_context_matched_pattern_index` to determine which pattern"]
|
||||
#[doc = " matched. You can also call `ts_query_context_matched_captures` to"]
|
||||
#[doc = " determine which nodes were captured by which capture names."]
|
||||
#[doc = " The cursor stores the state that is needed to iteratively search"]
|
||||
#[doc = " for matches. To use the query cursor:"]
|
||||
#[doc = " 1. First call `ts_query_cursor_exec` to start running a given query on"]
|
||||
#[doc = "a given syntax node."]
|
||||
#[doc = " 2. Then repeatedly call `ts_query_cursor_next` to iterate over the matches."]
|
||||
#[doc = " This will return `false` when there are no more matches left."]
|
||||
#[doc = " 3. After each successful call to `ts_query_cursor_next`, you can call"]
|
||||
#[doc = " `ts_query_cursor_matched_pattern_index` to determine which pattern"]
|
||||
#[doc = " matched. You can also call `ts_query_cursor_matched_captures` to"]
|
||||
#[doc = " determine which nodes were captured, and by which capture names."]
|
||||
#[doc = ""]
|
||||
#[doc = " If you don\'t care about finding all of the matches, you can stop calling"]
|
||||
#[doc = " `ts_query_context_next` at any point. And you can start executing the"]
|
||||
#[doc = " query against a different node by calling `ts_query_context_exec` again."]
|
||||
pub fn ts_query_context_new(arg1: *const TSQuery) -> *mut TSQueryContext;
|
||||
#[doc = " `ts_query_cursor_next` at any point. And you can start executing another"]
|
||||
#[doc = " query on another node by calling `ts_query_cursor_exec` again."]
|
||||
pub fn ts_query_cursor_new() -> *mut TSQueryCursor;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Delete a query context, freeing all of the memory that it used."]
|
||||
pub fn ts_query_context_delete(arg1: *mut TSQueryContext);
|
||||
#[doc = " Delete a query cursor, freeing all of the memory that it used."]
|
||||
pub fn ts_query_cursor_delete(arg1: *mut TSQueryCursor);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Start running a query on a given node."]
|
||||
pub fn ts_query_context_exec(arg1: *mut TSQueryContext, arg2: TSNode);
|
||||
#[doc = " Start running a given query on a given node."]
|
||||
pub fn ts_query_cursor_exec(arg1: *mut TSQueryCursor, arg2: *const TSQuery, arg3: TSNode);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Set the range of bytes or (row, column) positions in which the query"]
|
||||
#[doc = " will be executed."]
|
||||
pub fn ts_query_context_set_byte_range(arg1: *mut TSQueryContext, arg2: u32, arg3: u32);
|
||||
pub fn ts_query_cursor_set_byte_range(arg1: *mut TSQueryCursor, arg2: u32, arg3: u32);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_query_context_set_point_range(
|
||||
arg1: *mut TSQueryContext,
|
||||
arg2: TSPoint,
|
||||
arg3: TSPoint,
|
||||
);
|
||||
pub fn ts_query_cursor_set_point_range(arg1: *mut TSQueryCursor, arg2: TSPoint, arg3: TSPoint);
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Advance to the next match of the currently running query."]
|
||||
pub fn ts_query_context_next(arg1: *mut TSQueryContext) -> bool;
|
||||
pub fn ts_query_cursor_next(arg1: *mut TSQueryCursor) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Check which pattern matched."]
|
||||
pub fn ts_query_context_matched_pattern_index(arg1: *const TSQueryContext) -> u32;
|
||||
pub fn ts_query_cursor_matched_pattern_index(arg1: *const TSQueryCursor) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
#[doc = " Check which pattern matched."]
|
||||
pub fn ts_query_context_matched_captures(
|
||||
arg1: *const TSQueryContext,
|
||||
pub fn ts_query_cursor_matched_captures(
|
||||
arg1: *const TSQueryCursor,
|
||||
arg2: *mut u32,
|
||||
) -> *const TSQueryCapture;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue