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"
|
2015-12-04 20:20:29 -08:00
|
|
|
#include "runtime/length.h"
|
2014-06-26 08:52:42 -07:00
|
|
|
|
2015-12-22 14:37:29 -08:00
|
|
|
extern TSStateId TS_TREE_STATE_INDEPENDENT;
|
|
|
|
|
extern TSStateId TS_TREE_STATE_ERROR;
|
2015-12-21 16:04:11 -08: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-12-22 14:20:58 -08:00
|
|
|
|
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-12-22 14:20:58 -08:00
|
|
|
|
2015-07-31 15:47:48 -07:00
|
|
|
TSLength padding;
|
|
|
|
|
TSLength size;
|
2015-11-18 16:34:50 -08:00
|
|
|
|
2015-07-31 15:47:48 -07:00
|
|
|
TSSymbol symbol;
|
2015-12-22 14:20:58 -08:00
|
|
|
TSStateId lex_state;
|
|
|
|
|
TSStateId parse_state;
|
|
|
|
|
unsigned short ref_count;
|
|
|
|
|
bool visible : 1;
|
|
|
|
|
bool named : 1;
|
|
|
|
|
bool extra : 1;
|
|
|
|
|
bool fragile_left : 1;
|
|
|
|
|
bool fragile_right : 1;
|
|
|
|
|
bool has_changes : 1;
|
2014-06-26 08:52:42 -07:00
|
|
|
};
|
|
|
|
|
|
2015-12-04 20:20:29 -08:00
|
|
|
TSTree *ts_tree_make_leaf(TSSymbol, TSLength, TSLength, TSSymbolMetadata);
|
2015-11-22 13:32:20 -08:00
|
|
|
TSTree *ts_tree_make_node(TSSymbol, size_t, TSTree **, TSSymbolMetadata);
|
2015-12-15 22:28:50 -08:00
|
|
|
TSTree *ts_tree_make_copy(TSTree *child);
|
2015-12-04 20:20:29 -08:00
|
|
|
TSTree *ts_tree_make_error(TSLength, TSLength, char);
|
2015-09-13 19:47:45 -07:00
|
|
|
void ts_tree_retain(TSTree *tree);
|
|
|
|
|
void ts_tree_release(TSTree *tree);
|
|
|
|
|
bool ts_tree_eq(const TSTree *tree1, const TSTree *tree2);
|
2015-11-20 11:53:03 -08:00
|
|
|
int ts_tree_compare(const TSTree *tree1, const TSTree *tree2);
|
2015-11-25 11:08:44 -05:00
|
|
|
|
2015-12-04 20:20:29 -08:00
|
|
|
size_t ts_tree_start_column(const TSTree *self);
|
|
|
|
|
size_t ts_tree_end_column(const TSTree *self);
|
2015-12-02 07:53:15 -08:00
|
|
|
void ts_tree_set_children(TSTree *, size_t, TSTree **);
|
2015-11-15 12:21:16 -08:00
|
|
|
void ts_tree_assign_parents(TSTree *);
|
2015-09-13 19:47:45 -07:00
|
|
|
void ts_tree_edit(TSTree *, TSInputEdit);
|
2014-07-18 13:08:14 -07:00
|
|
|
|
2015-12-04 20:20:29 -08:00
|
|
|
static inline size_t ts_tree_total_chars(const TSTree *self) {
|
|
|
|
|
return self->padding.chars + self->size.chars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline TSLength ts_tree_total_size(const TSTree *self) {
|
|
|
|
|
return ts_length_add(self->padding, self->size);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-13 19:47:45 -07:00
|
|
|
static inline bool ts_tree_is_fragile(const TSTree *tree) {
|
2015-12-24 22:05:54 -08:00
|
|
|
return tree->fragile_left || tree->fragile_right ||
|
|
|
|
|
ts_tree_total_chars(tree) == 0;
|
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_
|