pub unsafe extern "C" fn ts_query_cursor_new() -> *mut TSQueryCursor
Expand description

Create a new cursor for executing a given query.

The cursor stores the state that is needed to iteratively search for matches. To use the query cursor, first call ts_query_cursor_exec to start running a given query on a given syntax node. Then, there are two options for consuming the results of the query:

  1. Repeatedly call ts_query_cursor_next_match to iterate over all of the matches in the order that they were found. Each match contains the index of the pattern that matched, and an array of captures. Because multiple patterns can match the same set of nodes, one match may contain captures that appear before some of the captures from a previous match.
  2. Repeatedly call ts_query_cursor_next_capture to iterate over all of the individual captures in the order that they appear. This is useful if don’t care about which pattern matched, and just want a single ordered sequence of captures.

If you don’t care about consuming all of the results, you can stop calling ts_query_cursor_next_match or ts_query_cursor_next_capture at any point. You can then start executing another query on another node by calling ts_query_cursor_exec again.