Clean up Tree code

This commit is contained in:
Max Brunsfeld 2014-09-01 14:08:07 -07:00
parent 88d07c8960
commit d38f095f01
2 changed files with 38 additions and 51 deletions

View file

@ -5,6 +5,7 @@
extern "C" {
#endif
#include <stdbool.h>
#include "tree_sitter/runtime.h"
typedef enum {
@ -46,30 +47,8 @@ static inline int ts_tree_is_wrapper(const TSTree *tree) {
return (tree->options & TSTreeOptionsWrapper);
}
static inline size_t ts_tree_visible_child_count(const TSTree *tree) {
if (tree->symbol == ts_builtin_sym_error)
return 0;
else
return tree->visible_child_count;
}
static inline TSTreeChild *ts_tree_visible_children(const TSTree *tree,
size_t *count) {
if (tree->symbol == ts_builtin_sym_error || tree->visible_child_count == 0) {
if (count)
*count = 0;
return NULL;
} else {
if (count)
*count = tree->visible_child_count;
return (TSTreeChild *)(tree + 1);
}
}
TSTree *ts_tree_make_leaf(TSSymbol symbol, size_t size, size_t padding,
int is_hidden);
TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
TSTree **children, int is_hidden);
TSTree *ts_tree_make_leaf(TSSymbol, size_t, size_t, bool);
TSTree *ts_tree_make_node(TSSymbol, size_t, TSTree **, bool);
TSTree *ts_tree_make_error(size_t size, size_t padding, char lookahead_char);
void ts_tree_retain(TSTree *tree);
void ts_tree_release(TSTree *tree);
@ -77,6 +56,7 @@ int ts_tree_equals(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);
TSTreeChild *ts_tree_visible_children(const TSTree *tree, size_t *count);
size_t ts_tree_total_size(const TSTree *tree);
#ifdef __cplusplus