tree-sitter/src/runtime/tree.h

91 lines
2.1 KiB
C
Raw Normal View History

#ifndef RUNTIME_TREE_H_
#define RUNTIME_TREE_H_
2014-07-17 23:29:11 -07:00
#ifdef __cplusplus
extern "C" {
#endif
2014-09-01 14:08:07 -07:00
#include <stdbool.h>
#include "tree_sitter/parser.h"
2014-06-28 18:45:22 -07:00
struct TSTree {
struct {
struct TSTree *parent;
size_t index;
TSLength offset;
} context;
2015-06-15 15:24:15 -07:00
size_t child_count;
2015-08-14 16:11:37 -07:00
size_t visible_child_count;
size_t named_child_count;
union {
2015-08-14 16:11:37 -07:00
struct TSTree **children;
char lookahead_char;
};
TSLength padding;
TSLength size;
TSSymbol symbol;
struct {
TSNodeType type : 2;
bool extra : 1;
bool fragile_left : 1;
bool fragile_right : 1;
2015-09-15 16:00:16 -07:00
bool has_changes : 1;
} options;
unsigned short int ref_count;
};
2014-07-18 13:08:14 -07:00
typedef struct {
2014-07-20 20:27:33 -07:00
TSTree *tree;
TSLength offset;
} TSTreeChild;
2014-07-18 13:08:14 -07:00
2014-10-22 12:55:01 -07:00
static inline bool ts_tree_is_extra(const TSTree *tree) {
return tree->options.extra;
}
2014-10-22 12:55:01 -07:00
static inline bool ts_tree_is_visible(const TSTree *tree) {
return tree->options.type != TSNodeTypeHidden;
}
static inline void ts_tree_set_extra(TSTree *tree) {
tree->options.extra = true;
}
static inline void ts_tree_set_fragile_left(TSTree *tree) {
tree->options.fragile_left = true;
}
static inline void ts_tree_set_fragile_right(TSTree *tree) {
tree->options.fragile_right = true;
}
static inline bool ts_tree_is_fragile_left(TSTree *tree) {
return tree->options.fragile_left;
}
static inline bool ts_tree_is_fragile_right(TSTree *tree) {
return tree->options.fragile_right;
}
TSTree *ts_tree_make_leaf(TSSymbol, TSLength, TSLength, TSNodeType);
TSTree *ts_tree_make_node(TSSymbol, size_t, TSTree **, TSNodeType);
TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_char);
2014-07-17 23:29:11 -07:00
void ts_tree_retain(TSTree *tree);
void ts_tree_release(TSTree *tree);
2014-10-03 16:06:08 -07:00
bool ts_tree_eq(const TSTree *tree1, const TSTree *tree2);
char *ts_tree_string(const TSTree *tree, const char **names);
char *ts_tree_error_string(const TSTree *tree, const char **names);
TSLength ts_tree_total_size(const TSTree *tree);
2015-08-22 10:48:34 -07:00
void ts_tree_prepend_children(TSTree *, size_t, TSTree **);
2015-09-15 16:00:16 -07:00
void ts_tree_edit(TSTree *, TSInputEdit);
2014-07-17 23:29:11 -07:00
2015-06-15 15:24:15 -07:00
static inline bool ts_tree_is_empty(TSTree *tree) {
return ts_tree_total_size(tree).bytes == 0;
}
2014-07-17 23:29:11 -07:00
#ifdef __cplusplus
}
#endif
#endif // RUNTIME_TREE_H_