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
|
|
|
|
2017-07-17 17:12:36 -07:00
|
|
|
typedef struct {
|
|
|
|
|
union {
|
|
|
|
|
char *long_data;
|
2018-04-02 18:04:26 -07:00
|
|
|
char short_data[sizeof(char *) + sizeof(uint32_t)];
|
2017-07-17 17:12:36 -07:00
|
|
|
};
|
2018-04-02 18:04:26 -07:00
|
|
|
uint32_t length;
|
2017-07-17 17:12:36 -07:00
|
|
|
} TSExternalTokenState;
|
|
|
|
|
|
2018-04-02 18:04:26 -07:00
|
|
|
typedef struct Tree Tree;
|
|
|
|
|
|
|
|
|
|
typedef Array(Tree *) TreeArray;
|
|
|
|
|
|
|
|
|
|
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;
|
2017-07-31 11:45:24 -07:00
|
|
|
TSSymbol alias_symbol : 15;
|
|
|
|
|
bool alias_is_named : 1;
|
2015-08-15 23:35:20 -07:00
|
|
|
} context;
|
2015-12-22 14:20:58 -08:00
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
Length padding;
|
|
|
|
|
Length size;
|
2018-04-02 18:04:26 -07:00
|
|
|
uint32_t ref_count;
|
2017-03-13 17:03:47 -07:00
|
|
|
uint32_t bytes_scanned;
|
2018-04-02 18:04:26 -07:00
|
|
|
uint32_t error_cost;
|
|
|
|
|
uint32_t node_count;
|
|
|
|
|
uint32_t repeat_depth;
|
|
|
|
|
uint32_t child_count;
|
|
|
|
|
int32_t dynamic_precedence;
|
2015-11-18 16:34:50 -08:00
|
|
|
|
2015-12-22 14:20:58 -08:00
|
|
|
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;
|
2017-12-28 15:48:35 -08:00
|
|
|
bool is_missing : 1;
|
2018-04-02 18:04:26 -07:00
|
|
|
TSSymbol symbol;
|
|
|
|
|
TSStateId parse_state;
|
|
|
|
|
struct {
|
|
|
|
|
TSSymbol symbol;
|
|
|
|
|
TSLexMode lex_mode;
|
|
|
|
|
} first_leaf;
|
2014-06-26 08:52:42 -07:00
|
|
|
|
2018-04-02 18:04:26 -07:00
|
|
|
union {
|
|
|
|
|
struct {
|
|
|
|
|
TreeArray children;
|
|
|
|
|
uint32_t visible_child_count;
|
|
|
|
|
uint32_t named_child_count;
|
|
|
|
|
uint16_t alias_sequence_id;
|
|
|
|
|
};
|
|
|
|
|
struct {
|
|
|
|
|
uint32_t _2;
|
|
|
|
|
TSExternalTokenState external_token_state;
|
|
|
|
|
};
|
|
|
|
|
struct {
|
|
|
|
|
uint32_t _1;
|
|
|
|
|
int32_t lookahead_char;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2016-09-22 18:02:11 -07:00
|
|
|
|
2017-10-05 17:32:21 -07:00
|
|
|
typedef struct {
|
|
|
|
|
TreeArray free_trees;
|
|
|
|
|
TreeArray tree_stack;
|
|
|
|
|
} TreePool;
|
|
|
|
|
|
|
|
|
|
void ts_external_token_state_init(TSExternalTokenState *, const char *, unsigned);
|
|
|
|
|
const char *ts_external_token_state_data(const TSExternalTokenState *);
|
2016-09-22 18:02:11 -07:00
|
|
|
|
2016-06-14 14:46:49 -07:00
|
|
|
bool ts_tree_array_copy(TreeArray, TreeArray *);
|
2017-10-05 17:32:21 -07:00
|
|
|
void ts_tree_array_delete(TreePool *, TreeArray *);
|
2017-02-19 13:53:28 -08:00
|
|
|
TreeArray ts_tree_array_remove_trailing_extras(TreeArray *);
|
2017-07-24 21:02:26 -07:00
|
|
|
void ts_tree_array_reverse(TreeArray *);
|
2016-02-22 09:23:25 -08:00
|
|
|
|
2017-10-05 17:32:21 -07:00
|
|
|
void ts_tree_pool_init(TreePool *);
|
|
|
|
|
void ts_tree_pool_delete(TreePool *);
|
|
|
|
|
Tree *ts_tree_pool_allocate(TreePool *);
|
|
|
|
|
void ts_tree_pool_free(TreePool *, Tree *);
|
|
|
|
|
|
|
|
|
|
Tree *ts_tree_make_leaf(TreePool *, TSSymbol, Length, Length, const TSLanguage *);
|
2018-04-02 18:04:26 -07:00
|
|
|
Tree *ts_tree_make_node(TreePool *, TSSymbol, TreeArray *, unsigned, const TSLanguage *);
|
2017-10-05 17:32:21 -07:00
|
|
|
Tree *ts_tree_make_copy(TreePool *, Tree *child);
|
|
|
|
|
Tree *ts_tree_make_error_node(TreePool *, TreeArray *, const TSLanguage *);
|
|
|
|
|
Tree *ts_tree_make_error(TreePool *, Length, Length, int32_t, const TSLanguage *);
|
2017-12-28 15:48:35 -08:00
|
|
|
Tree *ts_tree_make_missing_leaf(TreePool *, TSSymbol, const TSLanguage *);
|
2016-11-09 20:59:05 -08:00
|
|
|
void ts_tree_retain(Tree *tree);
|
2017-10-05 17:32:21 -07:00
|
|
|
void ts_tree_release(TreePool *, Tree *tree);
|
2016-11-09 20:59:05 -08:00
|
|
|
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);
|
2018-04-02 18:04:26 -07:00
|
|
|
void ts_tree_set_children(Tree *, TreeArray *, const TSLanguage *);
|
2017-10-05 17:32:21 -07:00
|
|
|
void ts_tree_assign_parents(Tree *, TreePool *, const TSLanguage *);
|
2016-11-09 20:59:05 -08:00
|
|
|
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 *);
|
2017-06-27 14:30:46 -07:00
|
|
|
Tree *ts_tree_last_external_token(Tree *);
|
|
|
|
|
bool ts_tree_external_token_state_eq(const Tree *, 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
|
|
|
}
|
|
|
|
|
|
2014-07-17 23:29:11 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-06-26 08:52:42 -07:00
|
|
|
#endif // RUNTIME_TREE_H_
|