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-07-17 23:29:11 -07:00
|
|
|
typedef enum {
|
2014-10-23 12:50:37 -07:00
|
|
|
TSTreeOptionsHidden = 1 << 0,
|
|
|
|
|
TSTreeOptionsExtra = 1 << 1,
|
|
|
|
|
TSTreeOptionsWrapper = 1 << 2,
|
2015-02-21 10:39:58 -08:00
|
|
|
TSTreeOptionsFragileLeft = 1 << 3,
|
|
|
|
|
TSTreeOptionsFragileRight = 1 << 4,
|
2014-07-17 23:29:11 -07:00
|
|
|
} TSTreeOptions;
|
|
|
|
|
|
2014-06-28 18:45:22 -07:00
|
|
|
struct TSTree {
|
2014-07-20 20:27:33 -07:00
|
|
|
TSSymbol symbol;
|
|
|
|
|
TSTreeOptions options;
|
|
|
|
|
size_t ref_count;
|
2014-09-26 16:15:07 -07:00
|
|
|
TSLength padding;
|
|
|
|
|
TSLength size;
|
2014-08-31 16:39:16 -07:00
|
|
|
char lookahead_char;
|
|
|
|
|
size_t child_count;
|
|
|
|
|
size_t visible_child_count;
|
|
|
|
|
struct TSTree **children;
|
2014-06-26 08:52:42 -07:00
|
|
|
};
|
|
|
|
|
|
2014-07-18 13:08:14 -07:00
|
|
|
typedef struct {
|
2014-07-20 20:27:33 -07:00
|
|
|
TSTree *tree;
|
2014-09-26 16:15:07 -07:00
|
|
|
TSLength offset;
|
2014-08-28 13:22:06 -07:00
|
|
|
} 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 & TSTreeOptionsExtra);
|
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) {
|
2014-07-20 20:27:33 -07:00
|
|
|
return !(tree->options & TSTreeOptionsHidden);
|
2014-07-16 18:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
2014-10-23 12:50:37 -07:00
|
|
|
static inline bool ts_tree_is_wrapper(const TSTree *tree) {
|
|
|
|
|
return !!(tree->options & TSTreeOptionsWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ts_tree_set_options(TSTree *tree, TSTreeOptions options) {
|
|
|
|
|
tree->options = (TSTreeOptions)(tree->options | options);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-16 18:38:06 -07:00
|
|
|
static inline void ts_tree_set_extra(TSTree *tree) {
|
2014-10-23 12:50:37 -07:00
|
|
|
ts_tree_set_options(tree, TSTreeOptionsExtra);
|
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) {
|
|
|
|
|
ts_tree_set_options(tree, TSTreeOptionsFragileLeft);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void ts_tree_set_fragile_right(TSTree *tree) {
|
|
|
|
|
ts_tree_set_options(tree, TSTreeOptionsFragileRight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_tree_is_fragile_left(TSTree *tree) {
|
|
|
|
|
return tree->options & TSTreeOptionsFragileLeft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_tree_is_fragile_right(TSTree *tree) {
|
|
|
|
|
return tree->options & TSTreeOptionsFragileRight;
|
2014-07-16 18:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
2014-09-26 16:15:07 -07:00
|
|
|
TSTree *ts_tree_make_leaf(TSSymbol, TSLength, TSLength, bool);
|
2014-09-01 14:08:07 -07:00
|
|
|
TSTree *ts_tree_make_node(TSSymbol, size_t, TSTree **, bool);
|
2014-09-26 16:15:07 -07:00
|
|
|
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);
|
2014-07-20 21:43:27 -07:00
|
|
|
char *ts_tree_string(const TSTree *tree, const char **names);
|
|
|
|
|
char *ts_tree_error_string(const TSTree *tree, const char **names);
|
|
|
|
|
TSTree **ts_tree_children(const TSTree *tree, size_t *count);
|
2014-09-01 14:08:07 -07:00
|
|
|
TSTreeChild *ts_tree_visible_children(const TSTree *tree, size_t *count);
|
2014-09-26 16:15:07 -07:00
|
|
|
TSLength ts_tree_total_size(const TSTree *tree);
|
2014-07-17 23:29:11 -07:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-06-26 08:52:42 -07:00
|
|
|
#endif // RUNTIME_TREE_H_
|