diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 20:22:09 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 20:22:09 +0100 |
| commit | 5a8dbc6347b3541e84fe669b22c17ad3b715e258 (patch) | |
| tree | b148c450939688caaaeb4adac6f2faa1eaffe649 /vendor/github.com/mitjafelicijan/go-tree-sitter/bindings.c | |
| download | qwe-editor-5a8dbc6347b3541e84fe669b22c17ad3b715e258.tar.gz | |
Engage!
Diffstat (limited to 'vendor/github.com/mitjafelicijan/go-tree-sitter/bindings.c')
| -rw-r--r-- | vendor/github.com/mitjafelicijan/go-tree-sitter/bindings.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/github.com/mitjafelicijan/go-tree-sitter/bindings.c b/vendor/github.com/mitjafelicijan/go-tree-sitter/bindings.c new file mode 100644 index 0000000..58d7994 --- /dev/null +++ b/vendor/github.com/mitjafelicijan/go-tree-sitter/bindings.c | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | #include "api.h" | ||
| 2 | #include "bindings.h" | ||
| 3 | #include <string.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | static void stderr_log(void *payload, TSLogType type, const char *msg) | ||
| 7 | { | ||
| 8 | bool include_lexing = (bool)payload; | ||
| 9 | switch (type) | ||
| 10 | { | ||
| 11 | case TSLogTypeParse: | ||
| 12 | fprintf(stderr, "* %s\n", msg); | ||
| 13 | break; | ||
| 14 | case TSLogTypeLex: | ||
| 15 | if (include_lexing) | ||
| 16 | fprintf(stderr, " %s\n", msg); | ||
| 17 | break; | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | TSLogger stderr_logger_new(bool include_lexing) | ||
| 22 | { | ||
| 23 | TSLogger result; | ||
| 24 | result.payload = (void *)include_lexing; | ||
| 25 | result.log = stderr_log; | ||
| 26 | return result; | ||
| 27 | } | ||
| 28 | |||
| 29 | const char *call_callReadFunc(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read) | ||
| 30 | { | ||
| 31 | ParsePayload *p = payload; | ||
| 32 | if (p->previous_content != NULL) | ||
| 33 | { | ||
| 34 | free(p->previous_content); | ||
| 35 | } | ||
| 36 | p->previous_content = callReadFunc(p->read_function_id, byte_index, position, bytes_read); | ||
| 37 | return p->previous_content; | ||
| 38 | } | ||
| 39 | |||
| 40 | TSTree *call_ts_parser_parse(TSParser *self, const TSTree *old_tree, int read_function_id, TSInputEncoding encoding) | ||
| 41 | { | ||
| 42 | ParsePayload payload = {read_function_id, NULL}; | ||
| 43 | TSInput input = {&payload, call_callReadFunc, encoding}; | ||
| 44 | TSTree *tree = ts_parser_parse(self, old_tree, input); | ||
| 45 | if (payload.previous_content != NULL) | ||
| 46 | { | ||
| 47 | free(payload.previous_content); | ||
| 48 | } | ||
| 49 | return tree; | ||
| 50 | } \ No newline at end of file | ||
