tree-sitter/include/tree_sitter/runtime.h

70 lines
2.1 KiB
C
Raw Normal View History

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-02-15 17:00:33 -08:00
#include <stdlib.h>
2014-02-20 18:38:31 -08:00
typedef int ts_symbol;
2014-02-26 19:03:43 -08:00
static const ts_symbol ts_builtin_sym_error = -1;
static const ts_symbol ts_builtin_sym_end = -2;
typedef struct ts_tree {
ts_symbol symbol;
2014-02-15 17:00:33 -08:00
size_t ref_count;
size_t offset;
size_t size;
union {
struct {
size_t count;
struct ts_tree **contents;
} children;
struct {
char lookahead_char;
size_t expected_input_count;
const ts_symbol *expected_inputs;
} error;
} data;
} ts_tree;
2014-02-15 17:00:33 -08:00
ts_tree * ts_tree_make_leaf(ts_symbol symbol, size_t size, size_t offset);
ts_tree * ts_tree_make_node(ts_symbol symbol, size_t child_count, ts_tree **children, size_t size, size_t offset);
ts_tree * ts_tree_make_error(char lookahead_char, size_t expected_input_count, const ts_symbol *expected_inputs, size_t size, size_t offset);
void ts_tree_retain(ts_tree *tree);
void ts_tree_release(ts_tree *tree);
int ts_tree_equals(const ts_tree *tree1, const ts_tree *tree2);
char * ts_tree_string(const ts_tree *tree, const char **names);
char * ts_tree_error_string(const ts_tree *tree, const char **names);
size_t ts_tree_child_count(const ts_tree *tree);
ts_tree ** ts_tree_children(const ts_tree *tree);
2014-02-15 17:00:33 -08:00
typedef struct {
void *data;
const char * (* read_fn)(void *data, size_t *bytes_read);
int (* seek_fn)(void *data, size_t position);
void (* release_fn)(void *data);
} ts_input;
2014-02-15 17:00:33 -08:00
typedef struct {
const ts_tree * (* parse_fn)(ts_input);
2014-02-15 17:00:33 -08:00
const char **symbol_names;
} ts_parse_config;
2014-02-15 17:00:33 -08:00
typedef struct ts_document ts_document;
2014-02-15 17:00:33 -08:00
ts_document * ts_document_make();
2014-03-09 22:05:17 -07:00
void ts_document_free(ts_document *doc);
void ts_document_set_parser(ts_document *doc, ts_parse_config parser);
void ts_document_set_input(ts_document *doc, ts_input input);
void ts_document_set_input_string(ts_document *doc, const char *text);
const ts_tree * ts_document_tree(const ts_document *doc);
const char * ts_document_string(const ts_document *doc);
2014-02-15 17:00:33 -08:00
#ifdef __cplusplus
}
#endif
2014-03-09 22:05:17 -07:00
#endif // TREE_SITTER_RUNTIME_H_