Get rid of string_input source file
There's not much in there now.
This commit is contained in:
parent
196d7f1355
commit
a24f7764d8
4 changed files with 24 additions and 55 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
#include "tree_sitter/runtime.h"
|
||||
#include "runtime/string_input.h"
|
||||
#include <string.h>
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
|
@ -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_
|
||||
Loading…
Add table
Add a link
Reference in a new issue