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"
|
2016-10-05 14:02:49 -07:00
|
|
|
#include "tree_sitter/runtime.h"
|
2015-12-04 20:20:29 -08:00
|
|
|
#include "runtime/length.h"
|
2016-02-22 09:23:25 -08:00
|
|
|
#include "runtime/array.h"
|
2016-06-22 21:04:35 -07:00
|
|
|
#include <stdio.h>
|
2014-06-26 08:52:42 -07:00
|
|
|
|
2016-06-27 14:39:12 -07:00
|
|
|
extern TSStateId TS_TREE_STATE_NONE;
|
2015-12-21 16:04:11 -08:00
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
typedef struct Tree {
|
2015-08-15 23:35:20 -07:00
|
|
|
struct {
|
2016-11-09 20:59:05 -08:00
|
|
|
struct Tree *parent;
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t index;
|
2016-11-09 20:59:05 -08:00
|
|
|
Length offset;
|
2015-08-15 23:35:20 -07:00
|
|
|
} context;
|
2015-12-22 14:20:58 -08:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t child_count;
|
2015-05-24 14:43:54 -07:00
|
|
|
union {
|
2016-12-20 13:12:01 -08:00
|
|
|
struct {
|
|
|
|
|
uint32_t visible_child_count;
|
|
|
|
|
uint32_t named_child_count;
|
|
|
|
|
struct Tree **children;
|
|
|
|
|
};
|
|
|
|
|
TSExternalTokenState external_token_state;
|
2016-09-03 22:45:02 -07:00
|
|
|
int32_t lookahead_char;
|
2015-05-24 14:43:54 -07:00
|
|
|
};
|
2015-12-22 14:20:58 -08:00
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
Length padding;
|
|
|
|
|
Length 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 parse_state;
|
2016-08-31 10:51:59 -07:00
|
|
|
unsigned error_cost;
|
2016-04-24 00:54:20 -07:00
|
|
|
|
2016-06-21 07:28:04 -07:00
|
|
|
struct {
|
|
|
|
|
TSSymbol symbol;
|
2016-12-20 17:06:20 -08:00
|
|
|
TSLexMode lex_mode;
|
2016-06-21 07:28:04 -07:00
|
|
|
} first_leaf;
|
|
|
|
|
|
2015-12-22 14:20:58 -08:00
|
|
|
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;
|
2016-12-20 17:06:20 -08:00
|
|
|
bool has_external_tokens : 1;
|
|
|
|
|
bool has_external_token_state : 1;
|
2016-11-09 20:59:05 -08:00
|
|
|
} Tree;
|
2014-06-26 08:52:42 -07:00
|
|
|
|
2016-09-22 18:02:11 -07:00
|
|
|
typedef struct {
|
2016-11-09 20:59:05 -08:00
|
|
|
Tree *tree;
|
|
|
|
|
Length position;
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t child_index;
|
2016-09-22 18:02:11 -07:00
|
|
|
} TreePathEntry;
|
|
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
typedef Array(Tree *) TreeArray;
|
2016-09-22 18:02:11 -07:00
|
|
|
|
|
|
|
|
typedef Array(TreePathEntry) TreePath;
|
|
|
|
|
|
2016-06-14 14:46:49 -07:00
|
|
|
bool ts_tree_array_copy(TreeArray, TreeArray *);
|
2016-03-07 16:03:23 -08:00
|
|
|
void ts_tree_array_delete(TreeArray *);
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_tree_array_essential_count(const TreeArray *);
|
2017-02-06 17:43:07 -08:00
|
|
|
TreeArray ts_tree_array_remove_last_n(TreeArray *, uint32_t);
|
2016-02-22 09:23:25 -08:00
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
Tree *ts_tree_make_leaf(TSSymbol, Length, Length, TSSymbolMetadata);
|
2016-11-14 12:15:24 -08:00
|
|
|
Tree *ts_tree_make_node(TSSymbol, uint32_t, Tree **, TSSymbolMetadata);
|
2016-11-09 20:59:05 -08:00
|
|
|
Tree *ts_tree_make_copy(Tree *child);
|
|
|
|
|
Tree *ts_tree_make_error_node(TreeArray *);
|
|
|
|
|
Tree *ts_tree_make_error(Length, Length, char);
|
|
|
|
|
void ts_tree_retain(Tree *tree);
|
|
|
|
|
void ts_tree_release(Tree *tree);
|
|
|
|
|
bool ts_tree_eq(const Tree *tree1, const Tree *tree2);
|
|
|
|
|
int ts_tree_compare(const Tree *tree1, const Tree *tree2);
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_tree_start_column(const Tree *self);
|
|
|
|
|
uint32_t ts_tree_end_column(const Tree *self);
|
|
|
|
|
void ts_tree_set_children(Tree *, uint32_t, Tree **);
|
2016-11-09 20:59:05 -08:00
|
|
|
void ts_tree_assign_parents(Tree *, TreePath *);
|
|
|
|
|
void ts_tree_edit(Tree *, const TSInputEdit *edit);
|
|
|
|
|
char *ts_tree_string(const Tree *, const TSLanguage *, bool include_all);
|
|
|
|
|
void ts_tree_print_dot_graph(const Tree *, const TSLanguage *, FILE *);
|
2016-12-21 13:59:56 -08:00
|
|
|
const TSExternalTokenState *ts_tree_last_external_token_state(const Tree *);
|
2016-11-09 20:59:05 -08:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline uint32_t ts_tree_total_bytes(const Tree *self) {
|
2016-09-13 13:08:52 -07:00
|
|
|
return self->padding.bytes + self->size.bytes;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
static inline Length ts_tree_total_size(const Tree *self) {
|
|
|
|
|
return length_add(self->padding, self->size);
|
2015-12-04 20:20:29 -08:00
|
|
|
}
|
|
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
static inline TSPoint ts_tree_total_extent(const Tree *self) {
|
|
|
|
|
return point_add(self->padding.extent, self->size.extent);
|
2016-09-13 13:08:52 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
static inline bool ts_tree_is_fragile(const Tree *tree) {
|
2015-12-24 22:05:54 -08:00
|
|
|
return tree->fragile_left || tree->fragile_right ||
|
2016-11-14 12:15:24 -08:00
|
|
|
ts_tree_total_bytes(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_
|