Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::ptr::{self, NonNull};

use regex_cursor::Cursor;

use crate::tree_sitter::query::Query;
use crate::tree_sitter::syntax_tree_node::SyntaxTreeNodeRaw;

enum QueryCursorData {}

pub struct QueryCaptures<'a> {
    query: &'a Query,
    query_cursor: &'a mut QueryCursorData,
    text_cursor: regex_cursor::RopeyCursor<'a>,
}

impl<C: Cursor> QueryCaptures<'_, C> {
    fn next(&mut self) {
        let mut query_match = TSQueryMatch {
            id: 0,
            pattern_index: 0,
            capture_count: 0,
            captures: ptr::null(),
        };
        let mut capture_idx = 0;
        loop {
            let success = unsafe {
                ts_query_cursor_next_capture(
                    &mut self.query_cursor,
                    &mut query_match,
                    &mut capture_idx,
                )
            };
            if !success {
                break;
            }
        }
        let mut input = regex_cursor::Input::new(self.text_cursor.clone());
    }
}

#[repr(C)]
#[derive(Debug)]
struct TSQueryCapture {
    node: SyntaxTreeNodeRaw,
    index: u32,
}

#[repr(C)]
#[derive(Debug)]
struct TSQueryMatch {
    id: u32,
    pattern_index: u16,
    capture_count: u16,
    captures: *const TSQueryCapture,
}

extern "C" {
    /// Advance to the next capture of the currently running query.
    /// If there is a capture, write its match to `*match` and its index within
    /// the matche's capture list to `*capture_index`. Otherwise, return `false`.
    fn ts_query_cursor_next_capture(
        self_: &mut QueryCursorData,
        match_: &mut TSQueryMatch,
        capture_index: &mut u32,
    ) -> bool;
}