Rework API completely
This commit is contained in:
parent
33f7643040
commit
e75ecd1bb1
31 changed files with 841 additions and 1075 deletions
|
|
@ -1,13 +1,7 @@
|
|||
#include "tree_sitter/runtime.h"
|
||||
#include "runtime/string_input.h"
|
||||
#include "runtime/alloc.h"
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
const char *string;
|
||||
uint32_t position;
|
||||
uint32_t length;
|
||||
} TSStringInput;
|
||||
|
||||
static const char *ts_string_input__read(void *payload, uint32_t *bytes_read) {
|
||||
TSStringInput *input = (TSStringInput *)payload;
|
||||
if (input->position >= input->length) {
|
||||
|
|
@ -26,17 +20,12 @@ static int ts_string_input__seek(void *payload, uint32_t byte, TSPoint _) {
|
|||
return (byte < input->length);
|
||||
}
|
||||
|
||||
TSInput ts_string_input_make(const char *string) {
|
||||
return ts_string_input_make_with_length(string, strlen(string));
|
||||
}
|
||||
|
||||
TSInput ts_string_input_make_with_length(const char *string, uint32_t length) {
|
||||
TSStringInput *input = ts_malloc(sizeof(TSStringInput));
|
||||
input->string = string;
|
||||
input->position = 0;
|
||||
input->length = length;
|
||||
return (TSInput){
|
||||
.payload = input,
|
||||
void ts_string_input_init(TSStringInput *self, const char *string, uint32_t length) {
|
||||
self->string = string;
|
||||
self->position = 0;
|
||||
self->length = length;
|
||||
self->input = (TSInput) {
|
||||
.payload = self,
|
||||
.read = ts_string_input__read,
|
||||
.seek = ts_string_input__seek,
|
||||
.encoding = TSInputEncodingUTF8,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue