1#ifndef TREE_SITTER_TREE_CURSOR_H_
2#define TREE_SITTER_TREE_CURSOR_H_
3
4#include "./subtree.h"
5
6typedef struct {
7 const Subtree *subtree;
8 Length position;
9 uint32_t child_index;
10 uint32_t structural_child_index;
11 uint32_t descendant_index;
12} TreeCursorEntry;
13
14typedef struct {
15 const TSTree *tree;
16 Array(TreeCursorEntry) stack;
17} TreeCursor;
18
19typedef enum {
20 TreeCursorStepNone,
21 TreeCursorStepHidden,
22 TreeCursorStepVisible,
23} TreeCursorStep;
24
25void ts_tree_cursor_init(TreeCursor *, TSNode);
26void ts_tree_cursor_current_status(
27 const TSTreeCursor *,
28 TSFieldId *,
29 bool *,
30 bool *,
31 bool *,
32 TSSymbol *,
33 unsigned *
34);
35
36TreeCursorStep ts_tree_cursor_goto_first_child_internal(TSTreeCursor *);
37TreeCursorStep ts_tree_cursor_goto_next_sibling_internal(TSTreeCursor *);
38
39static inline Subtree ts_tree_cursor_current_subtree(const TSTreeCursor *_self) {
40 const TreeCursor *self = (const TreeCursor *)_self;
41 TreeCursorEntry *last_entry = array_back(&self->stack);
42 return *last_entry->subtree;
43}
44
45TSNode ts_tree_cursor_parent_node(const TSTreeCursor *);
46
47#endif // TREE_SITTER_TREE_CURSOR_H_