Current section
6 Versions
Jump to
Current section
6 Versions
Compare versions
4
files changed
+17
additions
-7
deletions
| @@ -9,10 +9,17 @@ The package can be installed by adding `treesitter` to your list of dependencies | |
| 9 9 | ```elixir |
| 10 10 | def deps do |
| 11 11 | [ |
| 12 | - {:treesitter_elixir, "~> 0.1.1"} |
| 12 | + {:treesitter_elixir, "~> 0.1.3"} |
| 13 13 | ] |
| 14 14 | end |
| 15 15 | ``` |
| 16 16 | |
| 17 17 | Docs can be found on [hexdocs](https://hexdocs.pm/treesitter). |
| 18 18 | |
| 19 | + ## Tips |
| 20 | + |
| 21 | + If you like the library please consider buying me a coffee. This means I will be able to spend more time on developing it. |
| 22 | + You can tip me using ko-fi: |
| 23 | + |
| 24 | + [](https://ko-fi.com/U7U21LWO6I) |
| 25 | + |
| @@ -2,7 +2,7 @@ | |
| 2 2 | [{<<"issues">>,<<"https://codeberg.org/edwinvanl/treesitter_elixir/issues">>}, |
| 3 3 | {<<"source">>,<<"https://codeberg.org/edwinvanl/treesitter_elixir">>}]}. |
| 4 4 | {<<"name">>,<<"treesitter_elixir">>}. |
| 5 | - {<<"version">>,<<"0.1.2">>}. |
| 5 | + {<<"version">>,<<"0.1.3">>}. |
| 6 6 | {<<"description">>, |
| 7 7 | <<"Tree-sitter bindings (nif) for elixir. Currently small subset of the tree-sitter api is supported, but happy to accept merge requests/patches">>}. |
| 8 8 | {<<"elixir">>,<<"~> 1.18">>}. |
| @@ -6,7 +6,7 @@ defmodule Treesitter.MixProject do | |
| 6 6 | app: :treesitter_elixir, |
| 7 7 | description: |
| 8 8 | "Tree-sitter bindings (nif) for elixir. Currently small subset of the tree-sitter api is supported, but happy to accept merge requests/patches", |
| 9 | - version: "0.1.2", |
| 9 | + version: "0.1.3", |
| 10 10 | elixir: "~> 1.18", |
| 11 11 | compilers: [:elixir_make] ++ Mix.compilers(), |
| 12 12 | start_permanent: Mix.env() == :prod, |
| @@ -188,17 +188,18 @@ static ERL_NIF_TERM parse(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { | |
| 188 188 | enif_get_string_length(env, argv[1], &len, ERL_NIF_UTF8); |
| 189 189 | char *source_code = malloc(len + 1); |
| 190 190 | if (!enif_get_string(env, argv[1], source_code, len + 1, ERL_NIF_UTF8)) { |
| 191 | + free(source_code); |
| 191 192 | return to_error_string(env, "Failed loading source code"); |
| 192 193 | } |
| 193 194 | |
| 194 195 | TSTree *tree = ts_parser_parse_string(wrap->data, NULL, source_code, |
| 195 196 | strlen(source_code)); |
| 197 | + free(source_code); |
| 196 198 | if (!tree) { |
| 197 199 | return to_error_string(env, "Failed parsing the source code"); |
| 198 200 | } |
| 199 201 | WRTree *wraptree = enif_alloc_resource(tree_resource_type, sizeof(WRTree)); |
| 200 202 | wraptree->data = tree; |
| 201 | - free(source_code); |
| 202 203 | return to_ok_term(env, enif_make_resource(env, wraptree)); |
| 203 204 | } |
| 204 205 | static ERL_NIF_TERM enif_make_node_wrap(ErlNifEnv *env, const TSNode node) { |
| @@ -375,7 +376,8 @@ static ERL_NIF_TERM query_new(ErlNifEnv *env, int argc, | |
| 375 376 | enif_get_string_length(env, argv[1], &len, ERL_NIF_UTF8); |
| 376 377 | char *source_code = malloc(len + 1); |
| 377 378 | if (!enif_get_string(env, argv[1], source_code, len + 1, ERL_NIF_UTF8)) { |
| 378 | - return to_error_string(env, "Failed loading source code"); |
| 379 | + free(source_code); |
| 380 | + return to_error_string(env, "Failed loading query string"); |
| 379 381 | } |
| 380 382 | |
| 381 383 | WRQuery *wrap = enif_alloc_resource(query_resource_type, sizeof(WRQuery)); |
| @@ -383,13 +385,13 @@ static ERL_NIF_TERM query_new(ErlNifEnv *env, int argc, | |
| 383 385 | TSQueryError error_type; |
| 384 386 | wrap->data = ts_query_new(lang_wrap->data, source_code, len, &error_offset, |
| 385 387 | &error_type); |
| 388 | + free(source_code); |
| 386 389 | if (wrap->data) { |
| 387 390 | return to_ok_term(env, enif_make_resource(env, wrap)); |
| 388 391 | } |
| 389 392 | char error_string[50]; |
| 390 393 | sprintf(error_string, "Found an error in the query at %d, type %d", |
| 391 394 | error_offset, error_type); |
| 392 | - |
| 393 395 | return to_error_string(env, error_string); |
| 394 396 | } |
| 395 397 | |
| @@ -486,7 +488,8 @@ static ERL_NIF_TERM query_capture_name_for_id(ErlNifEnv *env, int argc, | |
| 486 488 | |
| 487 489 | uint32_t pattern_index; |
| 488 490 | enif_get_uint(env, argv[1], &pattern_index); |
| 489 | - int len; |
| 491 | + uint32_t len; |
| 492 | + // TODO: Free name? |
| 490 493 | const char *name = |
| 491 494 | ts_query_capture_name_for_id(query_wrap->data, pattern_index, &len); |
| 492 495 | return enif_make_tuple2(env, enif_make_atom(env, "ok"), |