1 #ifndef TREE_SITTER_SUBTREE_H_
2 #define TREE_SITTER_SUBTREE_H_
16 #include "tree_sitter/parser.h"
18 #define TS_TREE_STATE_NONE USHRT_MAX
19 #define NULL_SUBTREE ((Subtree) {.ptr = NULL})
52 #define SUBTREE_BITS \
56 bool has_changes : 1; \
57 bool is_missing : 1; \
60 #define SUBTREE_SIZE \
61 uint8_t padding_columns; \
62 uint8_t padding_rows : 4; \
63 uint8_t lookahead_bytes : 4; \
64 uint8_t padding_bytes; \
211 #define SUBTREE_GET(self, name) (self.data.is_inline ? self.data.name : self.ptr->name)
233 #define ts_subtree_children(self) \
234 ((self).data.is_inline ? NULL : (Subtree *)((self).ptr) - (self).ptr->child_count)
237 if (self->data.is_inline) {
238 self->data.extra = is_extra;
240 self->ptr->extra = is_extra;
245 if (
self.data.is_inline)
return self.data.symbol;
246 if (
self.ptr->child_count == 0)
return self.ptr->symbol;
247 return self.ptr->first_leaf.symbol;
251 if (
self.data.is_inline)
return self.data.parse_state;
252 if (
self.ptr->child_count == 0)
return self.ptr->parse_state;
253 return self.ptr->first_leaf.parse_state;
257 if (
self.data.is_inline) {
258 Length result = {
self.data.padding_bytes, {
self.data.padding_rows,
self.data.padding_columns}};
261 return self.ptr->padding;
266 if (
self.data.is_inline) {
267 Length result = {
self.data.size_bytes, {0,
self.data.size_bytes}};
270 return self.ptr->size;
283 return self.data.is_inline ? 0 :
self.ptr->child_count;
287 return self.data.is_inline ? 0 :
self.ptr->repeat_depth;
291 return (
self.data.is_inline ||
self.ptr->child_count == 0) ? 1 :
self.ptr->node_count;
296 return self.ptr->visible_child_count;
306 return self.data.is_inline ? 0 :
self.ptr->error_cost;
311 return (
self.data.is_inline ||
self.ptr->child_count == 0) ? 0 :
self.ptr->dynamic_precedence;
316 return self.ptr->production_id;
323 return self.data.is_inline ?
false :
self.ptr->fragile_left;
327 return self.data.is_inline ?
false :
self.ptr->fragile_right;
331 return self.data.is_inline ?
false :
self.ptr->has_external_tokens;
335 return self.data.is_inline ?
false :
self.ptr->depends_on_column;
339 return self.data.is_inline ?
false : (
self.ptr->fragile_left ||
self.ptr->fragile_right);
352 result.
data =
self.data;
358 result.
data =
self.data;
#define ERROR_COST_PER_RECOVERY
#define ERROR_COST_PER_MISSING_TREE
static Length length_add(Length len1, Length len2)
#define ts_builtin_sym_end
#define ts_builtin_sym_error
uint32_t visible_child_count
uint32_t named_child_count
int32_t dynamic_precedence
volatile uint32_t ref_count
ExternalScannerState external_scanner_state
SUBTREE_BITS uint8_t symbol
MutableSubtreeArray tree_stack
MutableSubtreeArray free_trees
char * ts_subtree_string(Subtree, const TSLanguage *, bool include_all)
static size_t ts_subtree_alloc_size(uint32_t child_count)
Subtree ts_subtree_new_error_node(SubtreeArray *, bool, const TSLanguage *)
static bool ts_subtree_fragile_left(Subtree self)
void ts_external_scanner_state_init(ExternalScannerState *, const char *, unsigned)
const char * ts_external_scanner_state_data(const ExternalScannerState *)
static bool ts_subtree_visible(Subtree self)
MutableSubtree ts_subtree_make_mut(SubtreePool *, Subtree)
static Subtree ts_subtree_from_mut(MutableSubtree self)
void ts_subtree_retain(Subtree)
void ts_subtree_balance(Subtree, SubtreePool *, const TSLanguage *)
Subtree ts_subtree_last_external_token(Subtree)
static bool ts_subtree_has_external_tokens(Subtree self)
static Length ts_subtree_total_size(Subtree self)
static MutableSubtree ts_subtree_to_mut_unsafe(Subtree self)
static uint32_t ts_subtree_total_bytes(Subtree self)
void ts_subtree_array_copy(SubtreeArray, SubtreeArray *)
static uint32_t ts_subtree_error_cost(Subtree self)
void ts_subtree_summarize(MutableSubtree, const Subtree *, uint32_t, const TSLanguage *)
void ts_subtree_print_dot_graph(Subtree, const TSLanguage *, FILE *)
void ts_subtree_summarize_children(MutableSubtree, const TSLanguage *)
typedef Array(Subtree) SubtreeArray
bool ts_subtree_external_scanner_state_eq(Subtree, Subtree)
static int32_t ts_subtree_dynamic_precedence(Subtree self)
static bool ts_subtree_extra(Subtree self)
Subtree ts_subtree_new_error(SubtreePool *, int32_t, Length, Length, uint32_t, TSStateId, const TSLanguage *)
static bool ts_subtree_is_keyword(Subtree self)
void ts_subtree_array_clear(SubtreePool *, SubtreeArray *)
static bool ts_subtree_is_error(Subtree self)
static bool ts_subtree_has_changes(Subtree self)
static bool ts_subtree_missing(Subtree self)
static uint16_t ts_subtree_production_id(Subtree self)
static Length ts_subtree_size(Subtree self)
static uint32_t ts_subtree_repeat_depth(Subtree self)
static TSSymbol ts_subtree_leaf_symbol(Subtree self)
static bool ts_subtree_depends_on_column(Subtree self)
Subtree ts_subtree_new_leaf(SubtreePool *, TSSymbol, Length, Length, uint32_t, TSStateId, bool, bool, bool, const TSLanguage *)
static bool ts_subtree_named(Subtree self)
static bool ts_subtree_is_fragile(Subtree self)
void ts_subtree_array_reverse(SubtreeArray *)
void ts_subtree_array_delete(SubtreePool *, SubtreeArray *)
static TSStateId ts_subtree_parse_state(Subtree self)
static uint32_t ts_subtree_lookahead_bytes(Subtree self)
SubtreePool ts_subtree_pool_new(uint32_t capacity)
void ts_subtree_array_remove_trailing_extras(SubtreeArray *, SubtreeArray *)
int ts_subtree_compare(Subtree, Subtree)
void ts_subtree_set_symbol(MutableSubtree *, TSSymbol, const TSLanguage *)
static uint32_t ts_subtree_visible_child_count(Subtree self)
static uint32_t ts_subtree_child_count(Subtree self)
static void ts_subtree_set_extra(MutableSubtree *self, bool is_extra)
void ts_subtree_release(SubtreePool *, Subtree)
static bool ts_subtree_is_eof(Subtree self)
#define SUBTREE_GET(self, name)
void ts_subtree_pool_delete(SubtreePool *)
static TSStateId ts_subtree_leaf_parse_state(Subtree self)
Subtree ts_subtree_new_missing_leaf(SubtreePool *, TSSymbol, Length, uint32_t, const TSLanguage *)
static Length ts_subtree_padding(Subtree self)
static uint32_t ts_subtree_node_count(Subtree self)
Subtree ts_subtree_edit(Subtree, const TSInputEdit *edit, SubtreePool *)
static bool ts_subtree_fragile_right(Subtree self)
static TSSymbol ts_subtree_symbol(Subtree self)
MutableSubtree ts_subtree_new_node(TSSymbol, SubtreeArray *, unsigned, const TSLanguage *)
const SubtreeHeapData * ptr