tree-sitter/src/runtime/tree.h

93 lines
2.4 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-07-17 23:29:11 -07:00
typedef enum {
TSTreeOptionsHidden = 1 << 0,
TSTreeOptionsExtra = 1 << 1,
TSTreeOptionsWrapper = 1 << 2,
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;
TSLength padding;
TSLength size;
union {
struct {
struct TSTree **children;
size_t child_count;
size_t visible_child_count;
};
char lookahead_char;
};
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 & TSTreeOptionsExtra);
}
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);
}
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);
}
static inline void ts_tree_set_extra(TSTree *tree) {
ts_tree_set_options(tree, TSTreeOptionsExtra);
}
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;
}
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);
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);
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);
TSLength ts_tree_total_size(const TSTree *tree);
2014-07-17 23:29:11 -07:00
#ifdef __cplusplus
}
#endif
#endif // RUNTIME_TREE_H_