Debian Codegraph @

Xtree-house/bindings/vendor/src/stack.h

raw
1 #ifndef TREE_SITTER_PARSE_STACK_H_
2 #define TREE_SITTER_PARSE_STACK_H_
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include "./array.h"
9 #include "./subtree.h"
10 #include <stdio.h>
11
12 typedef struct Stack Stack;
13
14 typedef unsigned StackVersion;
15 #define STACK_VERSION_NONE ((StackVersion)-1)
16
17 typedef struct {
18 SubtreeArray subtrees;
19 StackVersion version;
20 } StackSlice;
21 typedef Array(StackSlice) StackSliceArray;
22
23 typedef struct {
24 Length position;
25 unsigned depth;
26 TSStateId state;
27 } StackSummaryEntry;
28 typedef Array(StackSummaryEntry) StackSummary;
29
30 // Create a stack.
31 Stack *ts_stack_new(SubtreePool *subtree_pool);
32
33 // Release the memory reserved for a given stack.
34 void ts_stack_delete(Stack *self);
35
36 // Get the stack's current number of versions.
37 uint32_t ts_stack_version_count(const Stack *self);
38
39 // Get the stack's current number of halted versions.
40 uint32_t ts_stack_halted_version_count(Stack *self);
41
42 // Get the state at the top of the given version of the stack. If the stack is
43 // empty, this returns the initial state, 0.
44 TSStateId ts_stack_state(const Stack *self, StackVersion version);
45
46 // Get the last external token associated with a given version of the stack.
47 Subtree ts_stack_last_external_token(const Stack *self, StackVersion version);
48
49 // Set the last external token associated with a given version of the stack.
50 void ts_stack_set_last_external_token(Stack *self, StackVersion version, Subtree token);
51
52 // Get the position of the given version of the stack within the document.
53 Length ts_stack_position(const Stack *, StackVersion);
54
55 // Push a tree and state onto the given version of the stack.
56 //
57 // This transfers ownership of the tree to the Stack. Callers that
58 // need to retain ownership of the tree for their own purposes should
59 // first retain the tree.
60 void ts_stack_push(Stack *self, StackVersion version, Subtree subtree, bool pending, TSStateId state);
61
62 // Pop the given number of entries from the given version of the stack. This
63 // operation can increase the number of stack versions by revealing multiple
64 // versions which had previously been merged. It returns an array that
65 // specifies the index of each revealed version and the trees that were
66 // removed from that version.
67 StackSliceArray ts_stack_pop_count(Stack *self, StackVersion version, uint32_t count);
68
69 // Remove an error at the top of the given version of the stack.
70 SubtreeArray ts_stack_pop_error(Stack *self, StackVersion version);
71
72 // Remove any pending trees from the top of the given version of the stack.
73 StackSliceArray ts_stack_pop_pending(Stack *self, StackVersion version);
74
75 // Remove all trees from the given version of the stack.
76 StackSliceArray ts_stack_pop_all(Stack *self, StackVersion version);
77
78 // Get the maximum number of tree nodes reachable from this version of the stack
79 // since the last error was detected.
80 unsigned ts_stack_node_count_since_error(const Stack *self, StackVersion version);
81
82 int ts_stack_dynamic_precedence(Stack *self, StackVersion version);
83
84 bool ts_stack_has_advanced_since_error(const Stack *self, StackVersion version);
85
86 // Compute a summary of all the parse states near the top of the given
87 // version of the stack and store the summary for later retrieval.
88 void ts_stack_record_summary(Stack *self, StackVersion version, unsigned max_depth);
89
90 // Retrieve a summary of all the parse states near the top of the
91 // given version of the stack.
92 StackSummary *ts_stack_get_summary(Stack *self, StackVersion version);
93
94 // Get the total cost of all errors on the given version of the stack.
95 unsigned ts_stack_error_cost(const Stack *self, StackVersion version);
96
97 // Merge the given two stack versions if possible, returning true
98 // if they were successfully merged and false otherwise.
99 bool ts_stack_merge(Stack *self, StackVersion version1, StackVersion version2);
100
101 // Determine whether the given two stack versions can be merged.
102 bool ts_stack_can_merge(Stack *self, StackVersion version1, StackVersion version2);
103
104 Subtree ts_stack_resume(Stack *self, StackVersion version);
105
106 void ts_stack_pause(Stack *self, StackVersion version, Subtree lookahead);
107
108 void ts_stack_halt(Stack *self, StackVersion version);
109
110 bool ts_stack_is_active(const Stack *self, StackVersion version);
111
112 bool ts_stack_is_paused(const Stack *self, StackVersion version);
113
114 bool ts_stack_is_halted(const Stack *self, StackVersion version);
115
116 void ts_stack_renumber_version(Stack *self, StackVersion v1, StackVersion v2);
117
118 void ts_stack_swap_versions(Stack *, StackVersion v1, StackVersion v2);
119
120 StackVersion ts_stack_copy_version(Stack *self, StackVersion version);
121
122 // Remove the given version from the stack.
123 void ts_stack_remove_version(Stack *self, StackVersion version);
124
125 void ts_stack_clear(Stack *self);
126
127 bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f);
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif // TREE_SITTER_PARSE_STACK_H_