1pub const TREE_SITTER_LANGUAGE_VERSION: u32 = 14;
4pub const TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION: u32 = 13;
5pub type TSStateId = u16;
6pub type TSSymbol = u16;
7pub type TSFieldId = u16;
8#[repr(C)]
9#[derive(Debug)]
10pub struct TSLanguage {
11 _unused: [u8; 0],
12}
13#[repr(C)]
14#[derive(Debug)]
15pub struct TSParser {
16 _unused: [u8; 0],
17}
18#[repr(C)]
19#[derive(Debug)]
20pub struct TSTree {
21 _unused: [u8; 0],
22}
23#[repr(C)]
24#[derive(Debug)]
25pub struct TSQuery {
26 _unused: [u8; 0],
27}
28#[repr(C)]
29#[derive(Debug)]
30pub struct TSQueryCursor {
31 _unused: [u8; 0],
32}
33#[repr(C)]
34#[derive(Debug)]
35pub struct TSLookaheadIterator {
36 _unused: [u8; 0],
37}
38pub const TSInputEncodingUTF8: TSInputEncoding = 0;
39pub const TSInputEncodingUTF16: TSInputEncoding = 1;
40pub type TSInputEncoding = ::std::os::raw::c_uint;
41pub const TSSymbolTypeRegular: TSSymbolType = 0;
42pub const TSSymbolTypeAnonymous: TSSymbolType = 1;
43pub const TSSymbolTypeAuxiliary: TSSymbolType = 2;
44pub type TSSymbolType = ::std::os::raw::c_uint;
45#[repr(C)]
46#[derive(Debug, Copy, Clone)]
47pub struct TSPoint {
48 pub row: u32,
49 pub column: u32,
50}
51#[repr(C)]
52#[derive(Debug, Copy, Clone)]
53pub struct TSRange {
54 pub start_point: TSPoint,
55 pub end_point: TSPoint,
56 pub start_byte: u32,
57 pub end_byte: u32,
58}
59#[repr(C)]
60#[derive(Debug)]
61pub struct TSInput {
62 pub payload: *mut ::std::os::raw::c_void,
63 pub read: ::std::option::Option<
64 unsafe extern "C" fn(
65 payload: *mut ::std::os::raw::c_void,
66 byte_index: u32,
67 position: TSPoint,
68 bytes_read: *mut u32,
69 ) -> *const ::std::os::raw::c_char,
70 >,
71 pub encoding: TSInputEncoding,
72}
73pub const TSLogTypeParse: TSLogType = 0;
74pub const TSLogTypeLex: TSLogType = 1;
75pub type TSLogType = ::std::os::raw::c_uint;
76#[repr(C)]
77#[derive(Debug)]
78pub struct TSLogger {
79 pub payload: *mut ::std::os::raw::c_void,
80 pub log: ::std::option::Option<
81 unsafe extern "C" fn(
82 payload: *mut ::std::os::raw::c_void,
83 log_type: TSLogType,
84 buffer: *const ::std::os::raw::c_char,
85 ),
86 >,
87}
88#[repr(C)]
89#[derive(Debug, Copy, Clone)]
90pub struct TSInputEdit {
91 pub start_byte: u32,
92 pub old_end_byte: u32,
93 pub new_end_byte: u32,
94 pub start_point: TSPoint,
95 pub old_end_point: TSPoint,
96 pub new_end_point: TSPoint,
97}
98#[repr(C)]
99#[derive(Debug, Copy, Clone)]
100pub struct TSNode {
101 pub context: [u32; 4usize],
102 pub id: *const ::std::os::raw::c_void,
103 pub tree: *const TSTree,
104}
105#[repr(C)]
106#[derive(Debug, Copy, Clone)]
107pub struct TSTreeCursor {
108 pub tree: *const ::std::os::raw::c_void,
109 pub id: *const ::std::os::raw::c_void,
110 pub context: [u32; 2usize],
111}
112#[repr(C)]
113#[derive(Debug)]
114pub struct TSQueryCapture {
115 pub node: TSNode,
116 pub index: u32,
117}
118pub const TSQuantifierZero: TSQuantifier = 0;
119pub const TSQuantifierZeroOrOne: TSQuantifier = 1;
120pub const TSQuantifierZeroOrMore: TSQuantifier = 2;
121pub const TSQuantifierOne: TSQuantifier = 3;
122pub const TSQuantifierOneOrMore: TSQuantifier = 4;
123pub type TSQuantifier = ::std::os::raw::c_uint;
124#[repr(C)]
125#[derive(Debug)]
126pub struct TSQueryMatch {
127 pub id: u32,
128 pub pattern_index: u16,
129 pub capture_count: u16,
130 pub captures: *const TSQueryCapture,
131}
132pub const TSQueryPredicateStepTypeDone: TSQueryPredicateStepType = 0;
133pub const TSQueryPredicateStepTypeCapture: TSQueryPredicateStepType = 1;
134pub const TSQueryPredicateStepTypeString: TSQueryPredicateStepType = 2;
135pub type TSQueryPredicateStepType = ::std::os::raw::c_uint;
136#[repr(C)]
137#[derive(Debug)]
138pub struct TSQueryPredicateStep {
139 pub type_: TSQueryPredicateStepType,
140 pub value_id: u32,
141}
142pub const TSQueryErrorNone: TSQueryError = 0;
143pub const TSQueryErrorSyntax: TSQueryError = 1;
144pub const TSQueryErrorNodeType: TSQueryError = 2;
145pub const TSQueryErrorField: TSQueryError = 3;
146pub const TSQueryErrorCapture: TSQueryError = 4;
147pub const TSQueryErrorStructure: TSQueryError = 5;
148pub const TSQueryErrorLanguage: TSQueryError = 6;
149pub type TSQueryError = ::std::os::raw::c_uint;
150extern "C" {
151 #[doc = " Create a new parser."]
152 pub fn ts_parser_new() -> *mut TSParser;
153}
154extern "C" {
155 #[doc = " Delete the parser, freeing all of the memory that it used."]
156 pub fn ts_parser_delete(self_: *mut TSParser);
157}
158extern "C" {
159 #[doc = " Get the parser's current language."]
160 pub fn ts_parser_language(self_: *const TSParser) -> *const TSLanguage;
161}
162extern "C" {
163 #[doc = " Set the language that the parser should use for parsing.\n\n Returns a boolean indicating whether or not the language was successfully\n assigned. True means assignment succeeded. False means there was a version\n mismatch: the language was generated with an incompatible version of the\n Tree-sitter CLI. Check the language's version using [`ts_language_version`]\n and compare it to this library's [`TREE_SITTER_LANGUAGE_VERSION`] and\n [`TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION`] constants."]
164 pub fn ts_parser_set_language(self_: *mut TSParser, language: *const TSLanguage) -> bool;
165}
166extern "C" {
167 #[doc = " Set the ranges of text that the parser should include when parsing.\n\n By default, the parser will always include entire documents. This function\n allows you to parse only a *portion* of a document but still return a syntax\n tree whose ranges match up with the document as a whole. You can also pass\n multiple disjoint ranges.\n\n The second and third parameters specify the location and length of an array\n of ranges. The parser does *not* take ownership of these ranges; it copies\n the data, so it doesn't matter how these ranges are allocated.\n\n If `count` is zero, then the entire document will be parsed. Otherwise,\n the given ranges must be ordered from earliest to latest in the document,\n and they must not overlap. That is, the following must hold for all:\n\n `i < count - 1`: `ranges[i].end_byte <= ranges[i + 1].start_byte`\n\n If this requirement is not satisfied, the operation will fail, the ranges\n will not be assigned, and this function will return `false`. On success,\n this function returns `true`"]
168 pub fn ts_parser_set_included_ranges(
169 self_: *mut TSParser,
170 ranges: *const TSRange,
171 count: u32,
172 ) -> bool;
173}
174extern "C" {
175 #[doc = " Get the ranges of text that the parser will include when parsing.\n\n The returned pointer is owned by the parser. The caller should not free it\n or write to it. The length of the array will be written to the given\n `count` pointer."]
176 pub fn ts_parser_included_ranges(self_: *const TSParser, count: *mut u32) -> *const TSRange;
177}
178extern "C" {
179 #[doc = " Use the parser to parse some source code and create a syntax tree.\n\n If you are parsing this document for the first time, pass `NULL` for the\n `old_tree` parameter. Otherwise, if you have already parsed an earlier\n version of this document and the document has since been edited, pass the\n previous syntax tree so that the unchanged parts of it can be reused.\n This will save time and memory. For this to work correctly, you must have\n already edited the old syntax tree using the [`ts_tree_edit`] function in a\n way that exactly matches the source code changes.\n\n The [`TSInput`] parameter lets you specify how to read the text. It has the\n following three fields:\n 1. [`read`]: A function to retrieve a chunk of text at a given byte offset\n and (row, column) position. The function should return a pointer to the\n text and write its length to the [`bytes_read`] pointer. The parser does\n not take ownership of this buffer; it just borrows it until it has\n finished reading it. The function should write a zero value to the\n [`bytes_read`] pointer to indicate the end of the document.\n 2. [`payload`]: An arbitrary pointer that will be passed to each invocation\n of the [`read`] function.\n 3. [`encoding`]: An indication of how the text is encoded. Either\n `TSInputEncodingUTF8` or `TSInputEncodingUTF16`.\n\n This function returns a syntax tree on success, and `NULL` on failure. There\n are three possible reasons for failure:\n 1. The parser does not have a language assigned. Check for this using the\n[`ts_parser_language`] function.\n 2. Parsing was cancelled due to a timeout that was set by an earlier call to\n the [`ts_parser_set_timeout_micros`] function. You can resume parsing from\n where the parser left out by calling [`ts_parser_parse`] again with the\n same arguments. Or you can start parsing from scratch by first calling\n [`ts_parser_reset`].\n 3. Parsing was cancelled using a cancellation flag that was set by an\n earlier call to [`ts_parser_set_cancellation_flag`]. You can resume parsing\n from where the parser left out by calling [`ts_parser_parse`] again with\n the same arguments.\n\n [`read`]: TSInput::read\n [`payload`]: TSInput::payload\n [`encoding`]: TSInput::encoding\n [`bytes_read`]: TSInput::read"]
180 pub fn ts_parser_parse(
181 self_: *mut TSParser,
182 old_tree: *const TSTree,
183 input: TSInput,
184 ) -> *mut TSTree;
185}
186extern "C" {
187 #[doc = " Use the parser to parse some source code stored in one contiguous buffer.\n The first two parameters are the same as in the [`ts_parser_parse`] function\n above. The second two parameters indicate the location of the buffer and its\n length in bytes."]
188 pub fn ts_parser_parse_string(
189 self_: *mut TSParser,
190 old_tree: *const TSTree,
191 string: *const ::std::os::raw::c_char,
192 length: u32,
193 ) -> *mut TSTree;
194}
195extern "C" {
196 #[doc = " Use the parser to parse some source code stored in one contiguous buffer with\n a given encoding. The first four parameters work the same as in the\n [`ts_parser_parse_string`] method above. The final parameter indicates whether\n the text is encoded as UTF8 or UTF16."]
197 pub fn ts_parser_parse_string_encoding(
198 self_: *mut TSParser,
199 old_tree: *const TSTree,
200 string: *const ::std::os::raw::c_char,
201 length: u32,
202 encoding: TSInputEncoding,
203 ) -> *mut TSTree;
204}
205extern "C" {
206 #[doc = " Instruct the parser to start the next parse from the beginning.\n\n If the parser previously failed because of a timeout or a cancellation, then\n by default, it will resume where it left off on the next call to\n [`ts_parser_parse`] or other parsing functions. If you don't want to resume,\n and instead intend to use this parser to parse some other document, you must\n call [`ts_parser_reset`] first."]
207 pub fn ts_parser_reset(self_: *mut TSParser);
208}
209extern "C" {
210 #[doc = " Set the maximum duration in microseconds that parsing should be allowed to\n take before halting.\n\n If parsing takes longer than this, it will halt early, returning NULL.\n See [`ts_parser_parse`] for more information."]
211 pub fn ts_parser_set_timeout_micros(self_: *mut TSParser, timeout_micros: u64);
212}
213extern "C" {
214 #[doc = " Get the duration in microseconds that parsing is allowed to take."]
215 pub fn ts_parser_timeout_micros(self_: *const TSParser) -> u64;
216}
217extern "C" {
218 #[doc = " Set the parser's current cancellation flag pointer.\n\n If a non-null pointer is assigned, then the parser will periodically read\n from this pointer during parsing. If it reads a non-zero value, it will\n halt early, returning NULL. See [`ts_parser_parse`] for more information."]
219 pub fn ts_parser_set_cancellation_flag(self_: *mut TSParser, flag: *const usize);
220}
221extern "C" {
222 #[doc = " Get the parser's current cancellation flag pointer."]
223 pub fn ts_parser_cancellation_flag(self_: *const TSParser) -> *const usize;
224}
225extern "C" {
226 #[doc = " Set the logger that a parser should use during parsing.\n\n The parser does not take ownership over the logger payload. If a logger was\n previously assigned, the caller is responsible for releasing any memory\n owned by the previous logger."]
227 pub fn ts_parser_set_logger(self_: *mut TSParser, logger: TSLogger);
228}
229extern "C" {
230 #[doc = " Get the parser's current logger."]
231 pub fn ts_parser_logger(self_: *const TSParser) -> TSLogger;
232}
233extern "C" {
234 #[doc = " Set the file descriptor to which the parser should write debugging graphs\n during parsing. The graphs are formatted in the DOT language. You may want\n to pipe these graphs directly to a `dot(1)` process in order to generate\n SVG output. You can turn off this logging by passing a negative number."]
235 pub fn ts_parser_print_dot_graphs(self_: *mut TSParser, fd: ::std::os::raw::c_int);
236}
237extern "C" {
238 #[doc = " Create a shallow copy of the syntax tree. This is very fast.\n\n You need to copy a syntax tree in order to use it on more than one thread at\n a time, as syntax trees are not thread safe."]
239 pub fn ts_tree_copy(self_: *const TSTree) -> *mut TSTree;
240}
241extern "C" {
242 #[doc = " Delete the syntax tree, freeing all of the memory that it used."]
243 pub fn ts_tree_delete(self_: *mut TSTree);
244}
245extern "C" {
246 #[doc = " Get the root node of the syntax tree."]
247 pub fn ts_tree_root_node(self_: *const TSTree) -> TSNode;
248}
249extern "C" {
250 #[doc = " Get the root node of the syntax tree, but with its position\n shifted forward by the given offset."]
251 pub fn ts_tree_root_node_with_offset(
252 self_: *const TSTree,
253 offset_bytes: u32,
254 offset_extent: TSPoint,
255 ) -> TSNode;
256}
257extern "C" {
258 #[doc = " Get the language that was used to parse the syntax tree."]
259 pub fn ts_tree_language(self_: *const TSTree) -> *const TSLanguage;
260}
261extern "C" {
262 #[doc = " Get the array of included ranges that was used to parse the syntax tree.\n\n The returned pointer must be freed by the caller."]
263 pub fn ts_tree_included_ranges(self_: *const TSTree, length: *mut u32) -> *mut TSRange;
264}
265extern "C" {
266 #[doc = " Edit the syntax tree to keep it in sync with source code that has been\n edited.\n\n You must describe the edit both in terms of byte offsets and in terms of\n (row, column) coordinates."]
267 pub fn ts_tree_edit(self_: *mut TSTree, edit: *const TSInputEdit);
268}
269extern "C" {
270 #[doc = " Compare an old edited syntax tree to a new syntax tree representing the same\n document, returning an array of ranges whose syntactic structure has changed.\n\n For this to work correctly, the old syntax tree must have been edited such\n that its ranges match up to the new tree. Generally, you'll want to call\n this function right after calling one of the [`ts_parser_parse`] functions.\n You need to pass the old tree that was passed to parse, as well as the new\n tree that was returned from that function.\n\n The returned array is allocated using `malloc` and the caller is responsible\n for freeing it using `free`. The length of the array will be written to the\n given `length` pointer."]
271 pub fn ts_tree_get_changed_ranges(
272 old_tree: *const TSTree,
273 new_tree: *const TSTree,
274 length: *mut u32,
275 ) -> *mut TSRange;
276}
277extern "C" {
278 #[doc = " Write a DOT graph describing the syntax tree to the given file."]
279 pub fn ts_tree_print_dot_graph(self_: *const TSTree, file_descriptor: ::std::os::raw::c_int);
280}
281extern "C" {
282 #[doc = " Get the node's type as a null-terminated string."]
283 pub fn ts_node_type(self_: TSNode) -> *const ::std::os::raw::c_char;
284}
285extern "C" {
286 #[doc = " Get the node's type as a numerical id."]
287 pub fn ts_node_symbol(self_: TSNode) -> TSSymbol;
288}
289extern "C" {
290 #[doc = " Get the node's language."]
291 pub fn ts_node_language(self_: TSNode) -> *const TSLanguage;
292}
293extern "C" {
294 #[doc = " Get the node's type as it appears in the grammar ignoring aliases as a\n null-terminated string."]
295 pub fn ts_node_grammar_type(self_: TSNode) -> *const ::std::os::raw::c_char;
296}
297extern "C" {
298 #[doc = " Get the node's type as a numerical id as it appears in the grammar ignoring\n aliases. This should be used in [`ts_language_next_state`] instead of\n [`ts_node_symbol`]."]
299 pub fn ts_node_grammar_symbol(self_: TSNode) -> TSSymbol;
300}
301extern "C" {
302 #[doc = " Get the node's start byte."]
303 pub fn ts_node_start_byte(self_: TSNode) -> u32;
304}
305extern "C" {
306 #[doc = " Get the node's start position in terms of rows and columns."]
307 pub fn ts_node_start_point(self_: TSNode) -> TSPoint;
308}
309extern "C" {
310 #[doc = " Get the node's end byte."]
311 pub fn ts_node_end_byte(self_: TSNode) -> u32;
312}
313extern "C" {
314 #[doc = " Get the node's end position in terms of rows and columns."]
315 pub fn ts_node_end_point(self_: TSNode) -> TSPoint;
316}
317extern "C" {
318 #[doc = " Get an S-expression representing the node as a string.\n\n This string is allocated with `malloc` and the caller is responsible for\n freeing it using `free`."]
319 pub fn ts_node_string(self_: TSNode) -> *mut ::std::os::raw::c_char;
320}
321extern "C" {
322 #[doc = " Check if the node is null. Functions like [`ts_node_child`] and\n [`ts_node_next_sibling`] will return a null node to indicate that no such node\n was found."]
323 pub fn ts_node_is_null(self_: TSNode) -> bool;
324}
325extern "C" {
326 #[doc = " Check if the node is *named*. Named nodes correspond to named rules in the\n grammar, whereas *anonymous* nodes correspond to string literals in the\n grammar."]
327 pub fn ts_node_is_named(self_: TSNode) -> bool;
328}
329extern "C" {
330 #[doc = " Check if the node is *missing*. Missing nodes are inserted by the parser in\n order to recover from certain kinds of syntax errors."]
331 pub fn ts_node_is_missing(self_: TSNode) -> bool;
332}
333extern "C" {
334 #[doc = " Check if the node is *extra*. Extra nodes represent things like comments,\n which are not required the grammar, but can appear anywhere."]
335 pub fn ts_node_is_extra(self_: TSNode) -> bool;
336}
337extern "C" {
338 #[doc = " Check if a syntax node has been edited."]
339 pub fn ts_node_has_changes(self_: TSNode) -> bool;
340}
341extern "C" {
342 #[doc = " Check if the node is a syntax error or contains any syntax errors."]
343 pub fn ts_node_has_error(self_: TSNode) -> bool;
344}
345extern "C" {
346 #[doc = " Check if the node is a syntax error."]
347 pub fn ts_node_is_error(self_: TSNode) -> bool;
348}
349extern "C" {
350 #[doc = " Get this node's parse state."]
351 pub fn ts_node_parse_state(self_: TSNode) -> TSStateId;
352}
353extern "C" {
354 #[doc = " Get the parse state after this node."]
355 pub fn ts_node_next_parse_state(self_: TSNode) -> TSStateId;
356}
357extern "C" {
358 #[doc = " Get the node's immediate parent."]
359 pub fn ts_node_parent(self_: TSNode) -> TSNode;
360}
361extern "C" {
362 #[doc = " Get the node's child at the given index, where zero represents the first\n child."]
363 pub fn ts_node_child(self_: TSNode, child_index: u32) -> TSNode;
364}
365extern "C" {
366 #[doc = " Get the field name for node's child at the given index, where zero represents\n the first child. Returns NULL, if no field is found."]
367 pub fn ts_node_field_name_for_child(
368 self_: TSNode,
369 child_index: u32,
370 ) -> *const ::std::os::raw::c_char;
371}
372extern "C" {
373 #[doc = " Get the node's number of children."]
374 pub fn ts_node_child_count(self_: TSNode) -> u32;
375}
376extern "C" {
377 #[doc = " Get the node's *named* child at the given index.\n\n See also [`ts_node_is_named`]."]
378 pub fn ts_node_named_child(self_: TSNode, child_index: u32) -> TSNode;
379}
380extern "C" {
381 #[doc = " Get the node's number of *named* children.\n\n See also [`ts_node_is_named`]."]
382 pub fn ts_node_named_child_count(self_: TSNode) -> u32;
383}
384extern "C" {
385 #[doc = " Get the node's child with the given field name."]
386 pub fn ts_node_child_by_field_name(
387 self_: TSNode,
388 name: *const ::std::os::raw::c_char,
389 name_length: u32,
390 ) -> TSNode;
391}
392extern "C" {
393 #[doc = " Get the node's child with the given numerical field id.\n\n You can convert a field name to an id using the\n [`ts_language_field_id_for_name`] function."]
394 pub fn ts_node_child_by_field_id(self_: TSNode, field_id: TSFieldId) -> TSNode;
395}
396extern "C" {
397 #[doc = " Get the node's next / previous sibling."]
398 pub fn ts_node_next_sibling(self_: TSNode) -> TSNode;
399}
400extern "C" {
401 pub fn ts_node_prev_sibling(self_: TSNode) -> TSNode;
402}
403extern "C" {
404 #[doc = " Get the node's next / previous *named* sibling."]
405 pub fn ts_node_next_named_sibling(self_: TSNode) -> TSNode;
406}
407extern "C" {
408 pub fn ts_node_prev_named_sibling(self_: TSNode) -> TSNode;
409}
410extern "C" {
411 #[doc = " Get the node's first child that extends beyond the given byte offset."]
412 pub fn ts_node_first_child_for_byte(self_: TSNode, byte: u32) -> TSNode;
413}
414extern "C" {
415 #[doc = " Get the node's first named child that extends beyond the given byte offset."]
416 pub fn ts_node_first_named_child_for_byte(self_: TSNode, byte: u32) -> TSNode;
417}
418extern "C" {
419 #[doc = " Get the node's number of descendants, including one for the node itself."]
420 pub fn ts_node_descendant_count(self_: TSNode) -> u32;
421}
422extern "C" {
423 #[doc = " Get the smallest node within this node that spans the given range of bytes\n or (row, column) positions."]
424 pub fn ts_node_descendant_for_byte_range(self_: TSNode, start: u32, end: u32) -> TSNode;
425}
426extern "C" {
427 pub fn ts_node_descendant_for_point_range(
428 self_: TSNode,
429 start: TSPoint,
430 end: TSPoint,
431 ) -> TSNode;
432}
433extern "C" {
434 #[doc = " Get the smallest named node within this node that spans the given range of\n bytes or (row, column) positions."]
435 pub fn ts_node_named_descendant_for_byte_range(self_: TSNode, start: u32, end: u32) -> TSNode;
436}
437extern "C" {
438 pub fn ts_node_named_descendant_for_point_range(
439 self_: TSNode,
440 start: TSPoint,
441 end: TSPoint,
442 ) -> TSNode;
443}
444extern "C" {
445 #[doc = " Edit the node to keep it in-sync with source code that has been edited.\n\n This function is only rarely needed. When you edit a syntax tree with the\n [`ts_tree_edit`] function, all of the nodes that you retrieve from the tree\n afterward will already reflect the edit. You only need to use [`ts_node_edit`]\n when you have a [`TSNode`] instance that you want to keep and continue to use\n after an edit."]
446 pub fn ts_node_edit(self_: *mut TSNode, edit: *const TSInputEdit);
447}
448extern "C" {
449 #[doc = " Check if two nodes are identical."]
450 pub fn ts_node_eq(self_: TSNode, other: TSNode) -> bool;
451}
452extern "C" {
453 #[doc = " Create a new tree cursor starting from the given node.\n\n A tree cursor allows you to walk a syntax tree more efficiently than is\n possible using the [`TSNode`] functions. It is a mutable object that is always\n on a certain syntax node, and can be moved imperatively to different nodes."]
454 pub fn ts_tree_cursor_new(node: TSNode) -> TSTreeCursor;
455}
456extern "C" {
457 #[doc = " Delete a tree cursor, freeing all of the memory that it used."]
458 pub fn ts_tree_cursor_delete(self_: *mut TSTreeCursor);
459}
460extern "C" {
461 #[doc = " Re-initialize a tree cursor to start at a different node."]
462 pub fn ts_tree_cursor_reset(self_: *mut TSTreeCursor, node: TSNode);
463}
464extern "C" {
465 #[doc = " Re-initialize a tree cursor to the same position as another cursor.\n\n Unlike [`ts_tree_cursor_reset`], this will not lose parent information and\n allows reusing already created cursors."]
466 pub fn ts_tree_cursor_reset_to(dst: *mut TSTreeCursor, src: *const TSTreeCursor);
467}
468extern "C" {
469 #[doc = " Get the tree cursor's current node."]
470 pub fn ts_tree_cursor_current_node(self_: *const TSTreeCursor) -> TSNode;
471}
472extern "C" {
473 #[doc = " Get the field name of the tree cursor's current node.\n\n This returns `NULL` if the current node doesn't have a field.\n See also [`ts_node_child_by_field_name`]."]
474 pub fn ts_tree_cursor_current_field_name(
475 self_: *const TSTreeCursor,
476 ) -> *const ::std::os::raw::c_char;
477}
478extern "C" {
479 #[doc = " Get the field id of the tree cursor's current node.\n\n This returns zero if the current node doesn't have a field.\n See also [`ts_node_child_by_field_id`], [`ts_language_field_id_for_name`]."]
480 pub fn ts_tree_cursor_current_field_id(self_: *const TSTreeCursor) -> TSFieldId;
481}
482extern "C" {
483 #[doc = " Move the cursor to the parent of its current node.\n\n This returns `true` if the cursor successfully moved, and returns `false`\n if there was no parent node (the cursor was already on the root node)."]
484 pub fn ts_tree_cursor_goto_parent(self_: *mut TSTreeCursor) -> bool;
485}
486extern "C" {
487 #[doc = " Move the cursor to the next sibling of its current node.\n\n This returns `true` if the cursor successfully moved, and returns `false`\n if there was no next sibling node."]
488 pub fn ts_tree_cursor_goto_next_sibling(self_: *mut TSTreeCursor) -> bool;
489}
490extern "C" {
491 #[doc = " Move the cursor to the previous sibling of its current node.\n\n This returns `true` if the cursor successfully moved, and returns `false` if\n there was no previous sibling node.\n\n Note, that this function may be slower than\n [`ts_tree_cursor_goto_next_sibling`] due to how node positions are stored. In\n the worst case, this will need to iterate through all the children upto the\n previous sibling node to recalculate its position."]
492 pub fn ts_tree_cursor_goto_previous_sibling(self_: *mut TSTreeCursor) -> bool;
493}
494extern "C" {
495 #[doc = " Move the cursor to the first child of its current node.\n\n This returns `true` if the cursor successfully moved, and returns `false`\n if there were no children."]
496 pub fn ts_tree_cursor_goto_first_child(self_: *mut TSTreeCursor) -> bool;
497}
498extern "C" {
499 #[doc = " Move the cursor to the last child of its current node.\n\n This returns `true` if the cursor successfully moved, and returns `false` if\n there were no children.\n\n Note that this function may be slower than [`ts_tree_cursor_goto_first_child`]\n because it needs to iterate through all the children to compute the child's\n position."]
500 pub fn ts_tree_cursor_goto_last_child(self_: *mut TSTreeCursor) -> bool;
501}
502extern "C" {
503 #[doc = " Move the cursor to the node that is the nth descendant of\n the original node that the cursor was constructed with, where\n zero represents the original node itself."]
504 pub fn ts_tree_cursor_goto_descendant(self_: *mut TSTreeCursor, goal_descendant_index: u32);
505}
506extern "C" {
507 #[doc = " Get the index of the cursor's current node out of all of the\n descendants of the original node that the cursor was constructed with."]
508 pub fn ts_tree_cursor_current_descendant_index(self_: *const TSTreeCursor) -> u32;
509}
510extern "C" {
511 #[doc = " Get the depth of the cursor's current node relative to the original\n node that the cursor was constructed with."]
512 pub fn ts_tree_cursor_current_depth(self_: *const TSTreeCursor) -> u32;
513}
514extern "C" {
515 #[doc = " Move the cursor to the first child of its current node that extends beyond\n the given byte offset or point.\n\n This returns the index of the child node if one was found, and returns -1\n if no such child was found."]
516 pub fn ts_tree_cursor_goto_first_child_for_byte(
517 self_: *mut TSTreeCursor,
518 goal_byte: u32,
519 ) -> i64;
520}
521extern "C" {
522 pub fn ts_tree_cursor_goto_first_child_for_point(
523 self_: *mut TSTreeCursor,
524 goal_point: TSPoint,
525 ) -> i64;
526}
527extern "C" {
528 pub fn ts_tree_cursor_copy(cursor: *const TSTreeCursor) -> TSTreeCursor;
529}
530extern "C" {
531 #[doc = " Create a new query from a string containing one or more S-expression\n patterns. The query is associated with a particular language, and can\n only be run on syntax nodes parsed with that language.\n\n If all of the given patterns are valid, this returns a [`TSQuery`].\n If a pattern is invalid, this returns `NULL`, and provides two pieces\n of information about the problem:\n 1. The byte offset of the error is written to the `error_offset` parameter.\n 2. The type of error is written to the `error_type` parameter."]
532 pub fn ts_query_new(
533 language: *const TSLanguage,
534 source: *const ::std::os::raw::c_char,
535 source_len: u32,
536 error_offset: *mut u32,
537 error_type: *mut TSQueryError,
538 ) -> *mut TSQuery;
539}
540extern "C" {
541 #[doc = " Delete a query, freeing all of the memory that it used."]
542 pub fn ts_query_delete(self_: *mut TSQuery);
543}
544extern "C" {
545 #[doc = " Get the number of patterns, captures, or string literals in the query."]
546 pub fn ts_query_pattern_count(self_: *const TSQuery) -> u32;
547}
548extern "C" {
549 pub fn ts_query_capture_count(self_: *const TSQuery) -> u32;
550}
551extern "C" {
552 pub fn ts_query_string_count(self_: *const TSQuery) -> u32;
553}
554extern "C" {
555 #[doc = " Get the byte offset where the given pattern starts in the query's source.\n\n This can be useful when combining queries by concatenating their source\n code strings."]
556 pub fn ts_query_start_byte_for_pattern(self_: *const TSQuery, pattern_index: u32) -> u32;
557}
558extern "C" {
559 #[doc = " Get all of the predicates for the given pattern in the query.\n\n The predicates are represented as a single array of steps. There are three\n types of steps in this array, which correspond to the three legal values for\n the `type` field:\n - `TSQueryPredicateStepTypeCapture` - Steps with this type represent names\n of captures. Their `value_id` can be used with the\n [`ts_query_capture_name_for_id`] function to obtain the name of the capture.\n - `TSQueryPredicateStepTypeString` - Steps with this type represent literal\n strings. Their `value_id` can be used with the\n [`ts_query_string_value_for_id`] function to obtain their string value.\n - `TSQueryPredicateStepTypeDone` - Steps with this type are *sentinels*\n that represent the end of an individual predicate. If a pattern has two\n predicates, then there will be two steps with this `type` in the array."]
560 pub fn ts_query_predicates_for_pattern(
561 self_: *const TSQuery,
562 pattern_index: u32,
563 step_count: *mut u32,
564 ) -> *const TSQueryPredicateStep;
565}
566extern "C" {
567 pub fn ts_query_is_pattern_rooted(self_: *const TSQuery, pattern_index: u32) -> bool;
568}
569extern "C" {
570 pub fn ts_query_is_pattern_non_local(self_: *const TSQuery, pattern_index: u32) -> bool;
571}
572extern "C" {
573 pub fn ts_query_is_pattern_guaranteed_at_step(self_: *const TSQuery, byte_offset: u32) -> bool;
574}
575extern "C" {
576 #[doc = " Get the name and length of one of the query's captures, or one of the\n query's string literals. Each capture and string is associated with a\n numeric id based on the order that it appeared in the query's source."]
577 pub fn ts_query_capture_name_for_id(
578 self_: *const TSQuery,
579 index: u32,
580 length: *mut u32,
581 ) -> *const ::std::os::raw::c_char;
582}
583extern "C" {
584 #[doc = " Get the quantifier of the query's captures. Each capture is * associated\n with a numeric id based on the order that it appeared in the query's source."]
585 pub fn ts_query_capture_quantifier_for_id(
586 self_: *const TSQuery,
587 pattern_index: u32,
588 capture_index: u32,
589 ) -> TSQuantifier;
590}
591extern "C" {
592 pub fn ts_query_string_value_for_id(
593 self_: *const TSQuery,
594 index: u32,
595 length: *mut u32,
596 ) -> *const ::std::os::raw::c_char;
597}
598extern "C" {
599 #[doc = " Disable a certain capture within a query.\n\n This prevents the capture from being returned in matches, and also avoids\n any resource usage associated with recording the capture. Currently, there\n is no way to undo this."]
600 pub fn ts_query_disable_capture(
601 self_: *mut TSQuery,
602 name: *const ::std::os::raw::c_char,
603 length: u32,
604 );
605}
606extern "C" {
607 #[doc = " Disable a certain pattern within a query.\n\n This prevents the pattern from matching and removes most of the overhead\n associated with the pattern. Currently, there is no way to undo this."]
608 pub fn ts_query_disable_pattern(self_: *mut TSQuery, pattern_index: u32);
609}
610extern "C" {
611 #[doc = " Create a new cursor for executing a given query.\n\n The cursor stores the state that is needed to iteratively search\n for matches. To use the query cursor, first call [`ts_query_cursor_exec`]\n to start running a given query on a given syntax node. Then, there are\n two options for consuming the results of the query:\n 1. Repeatedly call [`ts_query_cursor_next_match`] to iterate over all of the\n *matches* in the order that they were found. Each match contains the\n index of the pattern that matched, and an array of captures. Because\n multiple patterns can match the same set of nodes, one match may contain\n captures that appear *before* some of the captures from a previous match.\n 2. Repeatedly call [`ts_query_cursor_next_capture`] to iterate over all of the\n individual *captures* in the order that they appear. This is useful if\n don't care about which pattern matched, and just want a single ordered\n sequence of captures.\n\n If you don't care about consuming all of the results, you can stop calling\n [`ts_query_cursor_next_match`] or [`ts_query_cursor_next_capture`] at any point.\n You can then start executing another query on another node by calling\n [`ts_query_cursor_exec`] again."]
612 pub fn ts_query_cursor_new() -> *mut TSQueryCursor;
613}
614extern "C" {
615 #[doc = " Delete a query cursor, freeing all of the memory that it used."]
616 pub fn ts_query_cursor_delete(self_: *mut TSQueryCursor);
617}
618extern "C" {
619 #[doc = " Start running a given query on a given node."]
620 pub fn ts_query_cursor_exec(self_: *mut TSQueryCursor, query: *const TSQuery, node: TSNode);
621}
622extern "C" {
623 #[doc = " Manage the maximum number of in-progress matches allowed by this query\n cursor.\n\n Query cursors have an optional maximum capacity for storing lists of\n in-progress captures. If this capacity is exceeded, then the\n earliest-starting match will silently be dropped to make room for further\n matches. This maximum capacity is optional — by default, query cursors allow\n any number of pending matches, dynamically allocating new space for them as\n needed as the query is executed."]
624 pub fn ts_query_cursor_did_exceed_match_limit(self_: *const TSQueryCursor) -> bool;
625}
626extern "C" {
627 pub fn ts_query_cursor_match_limit(self_: *const TSQueryCursor) -> u32;
628}
629extern "C" {
630 pub fn ts_query_cursor_set_match_limit(self_: *mut TSQueryCursor, limit: u32);
631}
632extern "C" {
633 #[doc = " Set the range of bytes or (row, column) positions in which the query\n will be executed."]
634 pub fn ts_query_cursor_set_byte_range(
635 self_: *mut TSQueryCursor,
636 start_byte: u32,
637 end_byte: u32,
638 );
639}
640extern "C" {
641 pub fn ts_query_cursor_set_point_range(
642 self_: *mut TSQueryCursor,
643 start_point: TSPoint,
644 end_point: TSPoint,
645 );
646}
647extern "C" {
648 #[doc = " Advance to the next match of the currently running query.\n\n If there is a match, write it to `*match` and return `true`.\n Otherwise, return `false`."]
649 pub fn ts_query_cursor_next_match(self_: *mut TSQueryCursor, match_: *mut TSQueryMatch)
650 -> bool;
651}
652extern "C" {
653 pub fn ts_query_cursor_remove_match(self_: *mut TSQueryCursor, match_id: u32);
654}
655extern "C" {
656 #[doc = " Advance to the next capture of the currently running query.\n\n If there is a capture, write its match to `*match` and its index within\n the matche's capture list to `*capture_index`. Otherwise, return `false`."]
657 pub fn ts_query_cursor_next_capture(
658 self_: *mut TSQueryCursor,
659 match_: *mut TSQueryMatch,
660 capture_index: *mut u32,
661 ) -> bool;
662}
663extern "C" {
664 #[doc = " Set the maximum start depth for a query cursor.\n\n This prevents cursors from exploring children nodes at a certain depth.\n Note if a pattern includes many children, then they will still be checked.\n\n The zero max start depth value can be used as a special behavior and\n it helps to destructure a subtree by staying on a node and using captures\n for interested parts. Note that the zero max start depth only limit a search\n depth for a pattern's root node but other nodes that are parts of the pattern\n may be searched at any depth what defined by the pattern structure.\n\n Set to `UINT32_MAX` to remove the maximum start depth."]
665 pub fn ts_query_cursor_set_max_start_depth(self_: *mut TSQueryCursor, max_start_depth: u32);
666}
667extern "C" {
668 #[doc = " Serialize a query."]
669 pub fn ts_query_serialize(
670 self_: *const TSQuery,
671 size: *mut usize,
672 ) -> *const ::std::os::raw::c_char;
673}
674extern "C" {
675 #[doc = " Deserialize a query."]
676 pub fn ts_query_deserialize(
677 src: *const ::std::os::raw::c_char,
678 language: *const TSLanguage,
679 ) -> *mut TSQuery;
680}
681extern "C" {
682 #[doc = " Get the number of distinct node types in the language."]
683 pub fn ts_language_symbol_count(self_: *const TSLanguage) -> u32;
684}
685extern "C" {
686 #[doc = " Get the number of valid states in this language."]
687 pub fn ts_language_state_count(self_: *const TSLanguage) -> u32;
688}
689extern "C" {
690 #[doc = " Get a node type string for the given numerical id."]
691 pub fn ts_language_symbol_name(
692 self_: *const TSLanguage,
693 symbol: TSSymbol,
694 ) -> *const ::std::os::raw::c_char;
695}
696extern "C" {
697 #[doc = " Get the numerical id for the given node type string."]
698 pub fn ts_language_symbol_for_name(
699 self_: *const TSLanguage,
700 string: *const ::std::os::raw::c_char,
701 length: u32,
702 is_named: bool,
703 ) -> TSSymbol;
704}
705extern "C" {
706 #[doc = " Get the number of distinct field names in the language."]
707 pub fn ts_language_field_count(self_: *const TSLanguage) -> u32;
708}
709extern "C" {
710 #[doc = " Get the field name string for the given numerical id."]
711 pub fn ts_language_field_name_for_id(
712 self_: *const TSLanguage,
713 id: TSFieldId,
714 ) -> *const ::std::os::raw::c_char;
715}
716extern "C" {
717 #[doc = " Get the numerical id for the given field name string."]
718 pub fn ts_language_field_id_for_name(
719 self_: *const TSLanguage,
720 name: *const ::std::os::raw::c_char,
721 name_length: u32,
722 ) -> TSFieldId;
723}
724extern "C" {
725 #[doc = " Check whether the given node type id belongs to named nodes, anonymous nodes,\n or a hidden nodes.\n\n See also [`ts_node_is_named`]. Hidden nodes are never returned from the API."]
726 pub fn ts_language_symbol_type(self_: *const TSLanguage, symbol: TSSymbol) -> TSSymbolType;
727}
728extern "C" {
729 #[doc = " Get the ABI version number for this language. This version number is used\n to ensure that languages were generated by a compatible version of\n Tree-sitter.\n\n See also [`ts_parser_set_language`]."]
730 pub fn ts_language_version(self_: *const TSLanguage) -> u32;
731}
732extern "C" {
733 #[doc = " Get the next parse state. Combine this with lookahead iterators to generate\n completion suggestions or valid symbols in error nodes. Use\n [`ts_node_grammar_symbol`] for valid symbols."]
734 pub fn ts_language_next_state(
735 self_: *const TSLanguage,
736 state: TSStateId,
737 symbol: TSSymbol,
738 ) -> TSStateId;
739}
740extern "C" {
741 #[doc = " Create a new lookahead iterator for the given language and parse state.\n\n This returns `NULL` if state is invalid for the language.\n\n Repeatedly using [`ts_lookahead_iterator_next`] and\n [`ts_lookahead_iterator_current_symbol`] will generate valid symbols in the\n given parse state. Newly created lookahead iterators will contain the `ERROR`\n symbol.\n\n Lookahead iterators can be useful to generate suggestions and improve syntax\n error diagnostics. To get symbols valid in an ERROR node, use the lookahead\n iterator on its first leaf node state. For `MISSING` nodes, a lookahead\n iterator created on the previous non-extra leaf node may be appropriate."]
742 pub fn ts_lookahead_iterator_new(
743 self_: *const TSLanguage,
744 state: TSStateId,
745 ) -> *mut TSLookaheadIterator;
746}
747extern "C" {
748 #[doc = " Delete a lookahead iterator freeing all the memory used."]
749 pub fn ts_lookahead_iterator_delete(self_: *mut TSLookaheadIterator);
750}
751extern "C" {
752 #[doc = " Reset the lookahead iterator to another state.\n\n This returns `true` if the iterator was reset to the given state and `false`\n otherwise."]
753 pub fn ts_lookahead_iterator_reset_state(
754 self_: *mut TSLookaheadIterator,
755 state: TSStateId,
756 ) -> bool;
757}
758extern "C" {
759 #[doc = " Reset the lookahead iterator.\n\n This returns `true` if the language was set successfully and `false`\n otherwise."]
760 pub fn ts_lookahead_iterator_reset(
761 self_: *mut TSLookaheadIterator,
762 language: *const TSLanguage,
763 state: TSStateId,
764 ) -> bool;
765}
766extern "C" {
767 #[doc = " Get the current language of the lookahead iterator."]
768 pub fn ts_lookahead_iterator_language(self_: *const TSLookaheadIterator) -> *const TSLanguage;
769}
770extern "C" {
771 #[doc = " Advance the lookahead iterator to the next symbol.\n\n This returns `true` if there is a new symbol and `false` otherwise."]
772 pub fn ts_lookahead_iterator_next(self_: *mut TSLookaheadIterator) -> bool;
773}
774extern "C" {
775 #[doc = " Get the current symbol of the lookahead iterator;"]
776 pub fn ts_lookahead_iterator_current_symbol(self_: *const TSLookaheadIterator) -> TSSymbol;
777}
778extern "C" {
779 #[doc = " Get the current symbol type of the lookahead iterator as a null terminated\n string."]
780 pub fn ts_lookahead_iterator_current_symbol_name(
781 self_: *const TSLookaheadIterator,
782 ) -> *const ::std::os::raw::c_char;
783}
784extern "C" {
785 #[doc = " Set the allocation functions used by the library.\n\n By default, Tree-sitter uses the standard libc allocation functions,\n but aborts the process when an allocation fails. This function lets\n you supply alternative allocation functions at runtime.\n\n If you pass `NULL` for any parameter, Tree-sitter will switch back to\n its default implementation of that function.\n\n If you call this function after the library has already been used, then\n you must ensure that either:\n 1. All the existing objects have been freed.\n 2. The new allocator shares its state with the old one, so it is capable\n of freeing memory that was allocated by the old allocator."]
786 pub fn ts_set_allocator(
787 new_malloc: ::std::option::Option<
788 unsafe extern "C" fn(arg1: usize) -> *mut ::std::os::raw::c_void,
789 >,
790 new_calloc: ::std::option::Option<
791 unsafe extern "C" fn(arg1: usize, arg2: usize) -> *mut ::std::os::raw::c_void,
792 >,
793 new_realloc: ::std::option::Option<
794 unsafe extern "C" fn(
795 arg1: *mut ::std::os::raw::c_void,
796 arg2: usize,
797 ) -> *mut ::std::os::raw::c_void,
798 >,
799 new_free: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void)>,
800 );
801}