tree-sitter/include/tree_sitter/runtime.h
Max Brunsfeld 1e79ed794b Allow multiple top-level nodes
Now, the root node of a document is always a document node.
It will often have only one child node which corresponds to the grammar's
start symbol, but not always. Currently, it may have more than one child
if there are ubiquitous tokens such as comments at the beginning of the
document. In the future, it will also be possible be possible to have multiple
for the document to have multiple children if the document is partially parsed.
2014-08-09 00:00:20 -07:00

60 lines
1.6 KiB
C

#ifndef TREE_SITTER_RUNTIME_H_
#define TREE_SITTER_RUNTIME_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
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);
} TSInput;
typedef struct {
size_t position;
size_t bytes_inserted;
size_t bytes_removed;
} TSInputEdit;
typedef unsigned short TSSymbol;
typedef struct TSLanguage TSLanguage;
typedef struct TSNode TSNode;
size_t ts_node_pos(const TSNode *);
size_t ts_node_size(const TSNode *);
TSSymbol ts_node_sym(const TSNode *);
TSNode *ts_node_child(TSNode *, size_t);
size_t ts_node_child_count(const TSNode *);
TSNode *ts_node_leaf_at_pos(TSNode *, size_t);
TSNode *ts_node_parent(TSNode *node);
TSNode *ts_node_next_sibling(TSNode *node);
TSNode *ts_node_prev_sibling(TSNode *node);
const char *ts_node_name(const TSNode *);
const char *ts_node_string(const TSNode *);
void ts_node_retain(TSNode *node);
void ts_node_release(TSNode *node);
int ts_node_eq(const TSNode *, const TSNode *);
typedef struct TSDocument TSDocument;
TSDocument *ts_document_make();
void ts_document_free(TSDocument *);
void ts_document_set_language(TSDocument *, const TSLanguage *);
void ts_document_set_input(TSDocument *, TSInput);
void ts_document_set_input_string(TSDocument *, const char *);
void ts_document_edit(TSDocument *, TSInputEdit);
TSNode *ts_document_root_node(const TSDocument *);
#define ts_builtin_sym_error 0
#define ts_builtin_sym_end 1
#define ts_builtin_sym_document 2
#define ts_builtin_sym_start 3
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_RUNTIME_H_