diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index 270800d4..4ab55ae0 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -16,7 +16,7 @@ typedef struct { typedef struct { void *payload; const char *(*read_fn)(void *payload, size_t *bytes_read); - int (*seek_fn)(void *payload, TSLength position); + int (*seek_fn)(void *payload, size_t character, size_t byte); } TSInput; typedef enum { diff --git a/spec/runtime/helpers/spy_input.cc b/spec/runtime/helpers/spy_input.cc index 764ae8ed..8d7ebdaf 100644 --- a/spec/runtime/helpers/spy_input.cc +++ b/spec/runtime/helpers/spy_input.cc @@ -84,11 +84,11 @@ const char * SpyInput::read(void *payload, size_t *bytes_read) { return spy->buffer; } -int SpyInput::seek(void *payload, TSLength position) { +int SpyInput::seek(void *payload, size_t character, size_t byte) { auto spy = static_cast(payload); if (spy->strings_read.size() == 0 || spy->strings_read.back().size() > 0) spy->strings_read.push_back(""); - spy->byte_offset = position.bytes; + spy->byte_offset = byte; return 0; } diff --git a/spec/runtime/helpers/spy_input.h b/spec/runtime/helpers/spy_input.h index b5f02eef..b2a0249c 100644 --- a/spec/runtime/helpers/spy_input.h +++ b/spec/runtime/helpers/spy_input.h @@ -19,7 +19,7 @@ class SpyInput { std::vector undo_stack; static const char * read(void *, size_t *); - static int seek(void *, TSLength); + static int seek(void *, size_t, size_t); std::string swap_substr(size_t, size_t, std::string); public: diff --git a/src/runtime/lexer.c b/src/runtime/lexer.c index bc6b5bd9..b443082c 100644 --- a/src/runtime/lexer.c +++ b/src/runtime/lexer.c @@ -24,7 +24,7 @@ static void ts_lexer__get_chunk(TSLexer *self) { TSInput input = self->input; if (!self->chunk || self->current_position.bytes != self->chunk_start + self->chunk_size) - input.seek_fn(input.payload, self->current_position); + input.seek_fn(input.payload, self->current_position.chars, self->current_position.bytes); self->chunk_start = self->current_position.bytes; self->chunk = input.read_fn(input.payload, &self->chunk_size); diff --git a/src/runtime/string_input.c b/src/runtime/string_input.c index d964ef40..5f91e759 100644 --- a/src/runtime/string_input.c +++ b/src/runtime/string_input.c @@ -19,10 +19,10 @@ const char *ts_string_input_read(void *payload, size_t *bytes_read) { return input->string + previous_position; } -int ts_string_input_seek(void *payload, TSLength position) { +int ts_string_input_seek(void *payload, size_t character, size_t byte) { TSStringInput *input = (TSStringInput *)payload; - input->position = position.bytes; - return (position.bytes < input->length); + input->position = byte; + return (byte < input->length); } TSInput ts_string_input_make(const char *string) {