Use individual args instead of TSLength in input seek function

This commit is contained in:
Max Brunsfeld 2015-12-03 23:06:01 -08:00
parent b3a6de6dad
commit 8e217f758c
5 changed files with 8 additions and 8 deletions

View file

@ -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 {

View file

@ -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<SpyInput *>(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;
}

View file

@ -19,7 +19,7 @@ class SpyInput {
std::vector<SpyInputEdit> 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:

View file

@ -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);

View file

@ -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) {