2014-03-09 22:05:17 -07:00
|
|
|
#ifndef TREE_SITTER_RUNTIME_H_
|
|
|
|
|
#define TREE_SITTER_RUNTIME_H_
|
2014-02-15 17:00:33 -08:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
2014-03-08 16:51:08 -08:00
|
|
|
|
2018-05-10 22:22:37 -07:00
|
|
|
#include <stdio.h>
|
2014-02-15 17:00:33 -08:00
|
|
|
#include <stdlib.h>
|
2016-11-14 12:15:24 -08:00
|
|
|
#include <stdint.h>
|
2014-10-03 16:06:08 -07:00
|
|
|
#include <stdbool.h>
|
2014-02-20 18:38:31 -08:00
|
|
|
|
2018-07-17 13:58:26 -07:00
|
|
|
#define TREE_SITTER_LANGUAGE_VERSION 9
|
2017-01-31 10:21:47 -08:00
|
|
|
|
2018-05-17 17:59:50 -07:00
|
|
|
typedef uint16_t TSSymbol;
|
2016-02-19 15:41:30 -08:00
|
|
|
typedef struct TSLanguage TSLanguage;
|
2018-05-10 22:22:37 -07:00
|
|
|
typedef struct TSParser TSParser;
|
|
|
|
|
typedef struct TSTree TSTree;
|
2016-02-19 15:41:30 -08:00
|
|
|
|
2015-12-28 10:40:53 -08:00
|
|
|
typedef enum {
|
|
|
|
|
TSInputEncodingUTF8,
|
|
|
|
|
TSInputEncodingUTF16,
|
|
|
|
|
} TSInputEncoding;
|
|
|
|
|
|
2017-04-12 09:46:01 -04:00
|
|
|
typedef enum {
|
|
|
|
|
TSSymbolTypeRegular,
|
|
|
|
|
TSSymbolTypeAnonymous,
|
|
|
|
|
TSSymbolTypeAuxiliary,
|
|
|
|
|
} TSSymbolType;
|
|
|
|
|
|
2018-02-14 07:31:49 -08:00
|
|
|
typedef struct {
|
|
|
|
|
uint32_t row;
|
|
|
|
|
uint32_t column;
|
|
|
|
|
} TSPoint;
|
|
|
|
|
|
2018-05-11 12:43:04 -07:00
|
|
|
typedef struct {
|
2018-06-20 11:46:44 -07:00
|
|
|
TSPoint start_point;
|
|
|
|
|
TSPoint end_point;
|
|
|
|
|
uint32_t start_byte;
|
|
|
|
|
uint32_t end_byte;
|
2018-05-11 12:43:04 -07:00
|
|
|
} TSRange;
|
|
|
|
|
|
2014-03-01 22:43:25 -08:00
|
|
|
typedef struct {
|
2015-09-08 23:33:43 -07:00
|
|
|
void *payload;
|
2018-06-19 09:34:40 -07:00
|
|
|
const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read);
|
2015-12-28 10:40:53 -08:00
|
|
|
TSInputEncoding encoding;
|
2014-06-28 18:56:04 -07:00
|
|
|
} TSInput;
|
2014-02-15 17:00:33 -08:00
|
|
|
|
2014-10-17 17:52:54 -07:00
|
|
|
typedef enum {
|
2016-09-06 17:27:50 -07:00
|
|
|
TSLogTypeParse,
|
|
|
|
|
TSLogTypeLex,
|
|
|
|
|
} TSLogType;
|
2014-10-17 17:52:54 -07:00
|
|
|
|
2014-10-13 01:02:12 -07:00
|
|
|
typedef struct {
|
2015-09-08 23:33:43 -07:00
|
|
|
void *payload;
|
2016-09-06 17:27:50 -07:00
|
|
|
void (*log)(void *payload, TSLogType, const char *);
|
|
|
|
|
} TSLogger;
|
2014-10-13 01:02:12 -07:00
|
|
|
|
2016-09-13 13:08:52 -07:00
|
|
|
typedef struct {
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t start_byte;
|
2018-05-17 11:14:51 -07:00
|
|
|
uint32_t old_end_byte;
|
|
|
|
|
uint32_t new_end_byte;
|
2016-09-13 13:08:52 -07:00
|
|
|
TSPoint start_point;
|
2018-05-17 11:14:51 -07:00
|
|
|
TSPoint old_end_point;
|
|
|
|
|
TSPoint new_end_point;
|
2016-09-13 13:08:52 -07:00
|
|
|
} TSInputEdit;
|
|
|
|
|
|
2015-07-31 15:47:48 -07:00
|
|
|
typedef struct {
|
2018-05-16 15:44:04 -07:00
|
|
|
uint32_t context[4];
|
2018-05-16 16:20:33 -07:00
|
|
|
const void *id;
|
2018-06-21 12:53:17 -07:00
|
|
|
const TSTree *tree;
|
2015-07-31 15:47:48 -07:00
|
|
|
} TSNode;
|
|
|
|
|
|
2018-05-16 16:05:08 -07:00
|
|
|
typedef struct {
|
2018-05-16 16:20:33 -07:00
|
|
|
const void *tree;
|
2018-11-07 15:11:21 -08:00
|
|
|
const void *id;
|
|
|
|
|
uint32_t context[2];
|
2018-05-16 16:05:08 -07:00
|
|
|
} TSTreeCursor;
|
|
|
|
|
|
2018-05-10 22:22:37 -07:00
|
|
|
TSParser *ts_parser_new();
|
|
|
|
|
void ts_parser_delete(TSParser *);
|
|
|
|
|
const TSLanguage *ts_parser_language(const TSParser *);
|
|
|
|
|
bool ts_parser_set_language(TSParser *, const TSLanguage *);
|
|
|
|
|
TSLogger ts_parser_logger(const TSParser *);
|
|
|
|
|
void ts_parser_set_logger(TSParser *, TSLogger);
|
2018-05-11 12:43:04 -07:00
|
|
|
void ts_parser_print_dot_graphs(TSParser *, FILE *);
|
2018-05-10 22:22:37 -07:00
|
|
|
void ts_parser_halt_on_error(TSParser *, bool);
|
|
|
|
|
TSTree *ts_parser_parse(TSParser *, const TSTree *, TSInput);
|
|
|
|
|
TSTree *ts_parser_parse_string(TSParser *, const TSTree *, const char *, uint32_t);
|
2018-11-27 15:43:21 -05:00
|
|
|
TSTree *ts_parser_parse_string_encoding(TSParser *, const TSTree *, const char *, uint32_t, TSInputEncoding);
|
2018-05-23 14:30:23 -07:00
|
|
|
bool ts_parser_enabled(const TSParser *);
|
2018-05-16 17:42:38 -07:00
|
|
|
void ts_parser_set_enabled(TSParser *, bool);
|
2018-05-23 14:30:23 -07:00
|
|
|
size_t ts_parser_operation_limit(const TSParser *);
|
|
|
|
|
void ts_parser_set_operation_limit(TSParser *, size_t);
|
2018-06-19 15:25:49 -07:00
|
|
|
void ts_parser_reset(TSParser *);
|
2018-06-20 12:51:39 -07:00
|
|
|
void ts_parser_set_included_ranges(TSParser *, const TSRange *, uint32_t);
|
|
|
|
|
const TSRange *ts_parser_included_ranges(const TSParser *, uint32_t *);
|
2018-05-10 22:22:37 -07:00
|
|
|
|
|
|
|
|
TSTree *ts_tree_copy(const TSTree *);
|
2018-05-11 15:06:13 -07:00
|
|
|
void ts_tree_delete(TSTree *);
|
2018-05-10 22:22:37 -07:00
|
|
|
TSNode ts_tree_root_node(const TSTree *);
|
|
|
|
|
void ts_tree_edit(TSTree *, const TSInputEdit *);
|
|
|
|
|
TSRange *ts_tree_get_changed_ranges(const TSTree *, const TSTree *, uint32_t *);
|
|
|
|
|
void ts_tree_print_dot_graph(const TSTree *, FILE *);
|
2018-06-21 12:54:19 -07:00
|
|
|
const TSLanguage *ts_tree_language(const TSTree *);
|
2018-05-09 16:38:56 -07:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_start_byte(TSNode);
|
2015-11-25 11:57:39 -05:00
|
|
|
TSPoint ts_node_start_point(TSNode);
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_end_byte(TSNode);
|
2015-11-25 11:57:39 -05:00
|
|
|
TSPoint ts_node_end_point(TSNode);
|
2015-09-08 23:16:24 -07:00
|
|
|
TSSymbol ts_node_symbol(TSNode);
|
2018-05-09 15:28:28 -07:00
|
|
|
const char *ts_node_type(TSNode);
|
|
|
|
|
char *ts_node_string(TSNode);
|
2015-09-08 23:16:24 -07:00
|
|
|
bool ts_node_eq(TSNode, TSNode);
|
2018-05-16 15:44:04 -07:00
|
|
|
bool ts_node_is_null(TSNode);
|
2015-09-08 23:16:24 -07:00
|
|
|
bool ts_node_is_named(TSNode);
|
2017-12-28 15:48:35 -08:00
|
|
|
bool ts_node_is_missing(TSNode);
|
2015-09-18 23:20:06 -07:00
|
|
|
bool ts_node_has_changes(TSNode);
|
2017-06-21 17:26:52 -07:00
|
|
|
bool ts_node_has_error(TSNode);
|
2015-09-08 23:16:24 -07:00
|
|
|
TSNode ts_node_parent(TSNode);
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_child(TSNode, uint32_t);
|
|
|
|
|
TSNode ts_node_named_child(TSNode, uint32_t);
|
|
|
|
|
uint32_t ts_node_child_count(TSNode);
|
|
|
|
|
uint32_t ts_node_named_child_count(TSNode);
|
2015-07-31 15:47:48 -07:00
|
|
|
TSNode ts_node_next_sibling(TSNode);
|
2015-09-08 23:16:24 -07:00
|
|
|
TSNode ts_node_next_named_sibling(TSNode);
|
2015-07-31 15:47:48 -07:00
|
|
|
TSNode ts_node_prev_sibling(TSNode);
|
2015-09-08 23:16:24 -07:00
|
|
|
TSNode ts_node_prev_named_sibling(TSNode);
|
2018-01-09 12:33:51 -08:00
|
|
|
TSNode ts_node_first_child_for_byte(TSNode, uint32_t);
|
|
|
|
|
TSNode ts_node_first_named_child_for_byte(TSNode, uint32_t);
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_descendant_for_byte_range(TSNode, uint32_t, uint32_t);
|
|
|
|
|
TSNode ts_node_named_descendant_for_byte_range(TSNode, uint32_t, uint32_t);
|
2016-09-06 21:17:26 -07:00
|
|
|
TSNode ts_node_descendant_for_point_range(TSNode, TSPoint, TSPoint);
|
|
|
|
|
TSNode ts_node_named_descendant_for_point_range(TSNode, TSPoint, TSPoint);
|
2018-07-11 16:17:46 -07:00
|
|
|
void ts_node_edit(TSNode *, const TSInputEdit *);
|
2014-07-17 23:29:11 -07:00
|
|
|
|
2018-06-21 12:54:04 -07:00
|
|
|
TSTreeCursor ts_tree_cursor_new(TSNode);
|
2018-05-09 16:38:56 -07:00
|
|
|
void ts_tree_cursor_delete(TSTreeCursor *);
|
2018-10-21 10:39:05 -07:00
|
|
|
void ts_tree_cursor_reset(TSTreeCursor *, TSNode);
|
|
|
|
|
TSNode ts_tree_cursor_current_node(const TSTreeCursor *);
|
|
|
|
|
bool ts_tree_cursor_goto_parent(TSTreeCursor *);
|
|
|
|
|
bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *);
|
2018-05-09 16:38:56 -07:00
|
|
|
bool ts_tree_cursor_goto_first_child(TSTreeCursor *);
|
2018-05-16 13:50:53 -07:00
|
|
|
int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *, uint32_t);
|
2018-05-09 16:38:56 -07:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_language_symbol_count(const TSLanguage *);
|
2016-02-19 15:41:30 -08:00
|
|
|
const char *ts_language_symbol_name(const TSLanguage *, TSSymbol);
|
2018-06-21 12:54:32 -07:00
|
|
|
TSSymbol ts_language_symbol_for_name(const TSLanguage *, const char *);
|
2017-04-12 09:47:51 -04:00
|
|
|
TSSymbolType ts_language_symbol_type(const TSLanguage *, TSSymbol);
|
2017-01-31 10:21:47 -08:00
|
|
|
uint32_t ts_language_version(const TSLanguage *);
|
2015-10-29 12:40:01 -04:00
|
|
|
|
2014-02-15 17:00:33 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-03-09 22:05:17 -07:00
|
|
|
#endif // TREE_SITTER_RUNTIME_H_
|