diff --git a/project.gyp b/project.gyp index 0006a18a..feeb1fac 100644 --- a/project.gyp +++ b/project.gyp @@ -94,7 +94,6 @@ 'src/runtime/node.c', 'src/runtime/stack.c', 'src/runtime/parser.c', - 'src/runtime/string_input.c', 'src/runtime/subtree.c', 'src/runtime/tree.c', 'src/runtime/tree_cursor.c', diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 58302445..7e0e6184 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -13,7 +13,6 @@ #include "runtime/reusable_node.h" #include "runtime/reduce_action.h" #include "runtime/error_costs.h" -#include "runtime/string_input.h" #include "runtime/tree.h" #define LOG(...) \ @@ -80,6 +79,24 @@ typedef enum { ErrorComparisonTakeRight, } ErrorComparison; +typedef struct { + const char *string; + uint32_t length; +} TSStringInput; + +// StringInput + +static const char *ts_string_input_read(void *_self, uint32_t byte, TSPoint _, uint32_t *length) { + TSStringInput *self = (TSStringInput *)_self; + if (byte >= self->length) { + *length = 0; + return ""; + } else { + *length = self->length - byte; + return self->string + byte; + } +} + // Parser - Private static void ts_parser__log(TSParser *self) { @@ -1474,7 +1491,10 @@ TSTree *ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input) { TSTree *ts_parser_parse_string(TSParser *self, const TSTree *old_tree, const char *string, uint32_t length) { - TSStringInput input; - ts_string_input_init(&input, string, length); - return ts_parser_parse(self, old_tree, ts_string_input_get(&input)); + TSStringInput input = {string, length}; + return ts_parser_parse(self, old_tree, (TSInput) { + &input, + ts_string_input_read, + TSInputEncodingUTF8, + }); } diff --git a/src/runtime/string_input.c b/src/runtime/string_input.c deleted file mode 100644 index 3ddc0c0d..00000000 --- a/src/runtime/string_input.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "tree_sitter/runtime.h" -#include "runtime/string_input.h" -#include - -static const char *ts_string_input__read(void *payload, uint32_t byte_offset, - TSPoint _, uint32_t *bytes_read) { - TSStringInput *input = (TSStringInput *)payload; - if (byte_offset >= input->length) { - *bytes_read = 0; - return ""; - } else { - *bytes_read = input->length - byte_offset; - return input->string + byte_offset; - } -} - -void ts_string_input_init(TSStringInput *self, const char *string, uint32_t length) { - self->string = string; - self->length = length; -} - -TSInput ts_string_input_get(TSStringInput *self) { - return (TSInput) { - .payload = self, - .read = ts_string_input__read, - .encoding = TSInputEncodingUTF8, - }; -} diff --git a/src/runtime/string_input.h b/src/runtime/string_input.h deleted file mode 100644 index b2e7536f..00000000 --- a/src/runtime/string_input.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef RUNTIME_STRING_INPUT_H_ -#define RUNTIME_STRING_INPUT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "tree_sitter/runtime.h" - -typedef struct { - const char *string; - uint32_t length; -} TSStringInput; - -void ts_string_input_init(TSStringInput *, const char *, uint32_t); -TSInput ts_string_input_get(TSStringInput *); - -#ifdef __cplusplus -} -#endif - -#endif // RUNTIME_STRING_INPUT_H_