2014-06-26 08:52:42 -07:00
|
|
|
#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>
|
2014-09-26 16:15:07 -07:00
|
|
|
#include "tree_sitter/parser.h"
|
2014-06-26 08:52:42 -07:00
|
|
|
|
2014-06-28 18:45:22 -07:00
|
|
|
struct TSTree {
|
2015-08-15 23:35:20 -07:00
|
|
|
struct {
|
|
|
|
|
struct TSTree *parent;
|
|
|
|
|
size_t index;
|
2015-09-08 21:43:37 -07:00
|
|
|
TSLength offset;
|
2015-08-15 23:35:20 -07:00
|
|
|
} 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;
|
2015-09-07 21:11:37 -07:00
|
|
|
size_t named_child_count;
|
2015-05-24 14:43:54 -07:00
|
|
|
union {
|
2015-08-14 16:11:37 -07:00
|
|
|
struct TSTree **children;
|
2015-05-24 14:43:54 -07:00
|
|
|
char lookahead_char;
|
|
|
|
|
};
|
2015-07-31 15:47:48 -07:00
|
|
|
TSLength padding;
|
|
|
|
|
TSLength size;
|
|
|
|
|
TSSymbol symbol;
|
2015-09-09 13:00:07 -07:00
|
|
|
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;
|
2015-09-09 13:00:07 -07:00
|
|
|
} options;
|
2015-05-24 14:43:54 -07:00
|
|
|
unsigned short int ref_count;
|
2014-06-26 08:52:42 -07:00
|
|
|
};
|
|
|
|
|
|
2015-09-13 19:47:45 -07:00
|
|
|
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);
|
|
|
|
|
void ts_tree_retain(TSTree *tree);
|
|
|
|
|
void ts_tree_release(TSTree *tree);
|
|
|
|
|
bool ts_tree_eq(const TSTree *tree1, const TSTree *tree2);
|
2015-10-28 12:09:28 -07:00
|
|
|
char *ts_tree_string(const TSTree *tree, const char **names,
|
|
|
|
|
bool include_anonymous);
|
2015-09-13 19:47:45 -07:00
|
|
|
TSLength ts_tree_total_size(const TSTree *tree);
|
|
|
|
|
void ts_tree_prepend_children(TSTree *, size_t, TSTree **);
|
|
|
|
|
void ts_tree_edit(TSTree *, TSInputEdit);
|
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) {
|
2015-09-05 22:29:17 -07:00
|
|
|
return tree->options.extra;
|
2014-07-16 18:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
2014-10-22 12:55:01 -07:00
|
|
|
static inline bool ts_tree_is_visible(const TSTree *tree) {
|
2015-09-07 21:11:37 -07:00
|
|
|
return tree->options.type != TSNodeTypeHidden;
|
2014-10-23 12:50:37 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-16 18:38:06 -07:00
|
|
|
static inline void ts_tree_set_extra(TSTree *tree) {
|
2015-09-05 22:29:17 -07:00
|
|
|
tree->options.extra = true;
|
2014-07-16 18:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
2015-02-21 10:39:58 -08:00
|
|
|
static inline void ts_tree_set_fragile_left(TSTree *tree) {
|
2015-09-05 22:29:17 -07:00
|
|
|
tree->options.fragile_left = true;
|
2015-02-21 10:39:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ts_tree_set_fragile_right(TSTree *tree) {
|
2015-09-05 22:29:17 -07:00
|
|
|
tree->options.fragile_right = true;
|
2015-02-21 10:39:58 -08:00
|
|
|
}
|
|
|
|
|
|
2015-09-13 19:47:45 -07:00
|
|
|
static inline bool ts_tree_is_fragile_left(const TSTree *tree) {
|
2015-09-05 22:29:17 -07:00
|
|
|
return tree->options.fragile_left;
|
2015-02-21 10:39:58 -08:00
|
|
|
}
|
|
|
|
|
|
2015-09-13 19:47:45 -07:00
|
|
|
static inline bool ts_tree_is_fragile_right(const TSTree *tree) {
|
2015-09-05 22:29:17 -07:00
|
|
|
return tree->options.fragile_right;
|
2014-07-16 18:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
2015-09-13 19:47:45 -07:00
|
|
|
static inline bool ts_tree_is_terminal(const TSTree *tree) {
|
|
|
|
|
return tree->child_count == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_tree_has_changes(const TSTree *tree) {
|
|
|
|
|
return tree->options.has_changes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_tree_is_empty(const TSTree *tree) {
|
|
|
|
|
return ts_tree_total_size(tree).chars == 0;
|
|
|
|
|
}
|
2014-07-17 23:29:11 -07:00
|
|
|
|
2015-09-13 19:47:45 -07:00
|
|
|
static inline bool ts_tree_is_fragile(const TSTree *tree) {
|
|
|
|
|
return ts_tree_is_empty(tree) || tree->options.fragile_left ||
|
|
|
|
|
tree->options.fragile_right;
|
2015-06-15 15:24:15 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-06-26 08:52:42 -07:00
|
|
|
#endif // RUNTIME_TREE_H_
|