Skip to content

Commit

Permalink
feat: update to tree-sitter v0.25.2 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidelettieri authored Feb 21, 2025
1 parent 2fa3a24 commit 368f5db
Show file tree
Hide file tree
Showing 29 changed files with 302 additions and 22 deletions.
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
// Path is relataive to the devcontainer.json file.
"dockerfile": "DOCKERFILE"
},

"runArgs": [
"--userns=keep-id"
],

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand Down
2 changes: 1 addition & 1 deletion GenerateTreeSitterEmbeddedTemplate.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unix-types
/lib64/clang/16/include
tree-sitter/lib/include
--file
tree-sitter-embedded-template/bindings/c/tree-sitter-embedded_template.h
tree-sitter-embedded-template/bindings/c/tree-sitter-embedded-template.h
--output
./src/TreeSitter.Bindings/EmbdeddedTemplate
--test-output
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages-definitions/libtreesitter/runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"runtimes": {
"linux-x64": {
"libtreesitter": {
"libtreesitter.runtime.linux-x64": "0.22.6"
"libtreesitter.runtime.linux-x64": "0.25.2"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cd tree-sitter-ruby
make clean
make
cd ..
cp tree-sitter/libtree-sitter.so.0 packages-definitions/libtreesitter.runtime.linux-x64/libtree-sitter.so
cp tree-sitter/libtree-sitter.so packages-definitions/libtreesitter.runtime.linux-x64/libtree-sitter.so
cp tree-sitter-json/libtree-sitter-json.so packages-definitions/libtreesitter.runtime.linux-x64/libtree-sitter-json.so
cp tree-sitter-html/libtree-sitter-html.so packages-definitions/libtreesitter.runtime.linux-x64/libtree-sitter-html.so
cp tree-sitter-embedded-template/libtree-sitter-embedded_template.so packages-definitions/libtreesitter.runtime.linux-x64/libtree-sitter-embedded-template.so
Expand Down
63 changes: 53 additions & 10 deletions src/TreeSitter.Bindings/TSBindingsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public static unsafe partial class TSBindingsParser
[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_parser_parse", ExactSpelling = true)]
public static extern TSTree* parser_parse(TSParser* self, [NativeTypeName("const TSTree *")] TSTree* old_tree, TSInput input);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_parser_parse_with_options", ExactSpelling = true)]
public static extern TSTree* parser_parse_with_options(TSParser* self, [NativeTypeName("const TSTree *")] TSTree* old_tree, TSInput input, TSParseOptions parse_options);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_parser_parse_string", ExactSpelling = true)]
public static extern TSTree* parser_parse_string(TSParser* self, [NativeTypeName("const TSTree *")] TSTree* old_tree, [NativeTypeName("const char *")] sbyte* @string, [NativeTypeName("uint32_t")] uint length);

Expand Down Expand Up @@ -166,8 +169,8 @@ public static unsafe partial class TSBindingsParser
[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_parent", ExactSpelling = true)]
public static extern TSNode node_parent(TSNode self);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_child_containing_descendant", ExactSpelling = true)]
public static extern TSNode node_child_containing_descendant(TSNode self, TSNode descendant);
[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_child_with_descendant", ExactSpelling = true)]
public static extern TSNode node_child_with_descendant(TSNode self, TSNode descendant);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_child", ExactSpelling = true)]
public static extern TSNode node_child(TSNode self, [NativeTypeName("uint32_t")] uint child_index);
Expand All @@ -176,6 +179,10 @@ public static unsafe partial class TSBindingsParser
[return: NativeTypeName("const char *")]
public static extern sbyte* node_field_name_for_child(TSNode self, [NativeTypeName("uint32_t")] uint child_index);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_field_name_for_named_child", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
public static extern sbyte* node_field_name_for_named_child(TSNode self, [NativeTypeName("uint32_t")] uint named_child_index);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_child_count", ExactSpelling = true)]
[return: NativeTypeName("uint32_t")]
public static extern uint node_child_count(TSNode self);
Expand Down Expand Up @@ -321,6 +328,10 @@ public static unsafe partial class TSBindingsParser
[return: NativeTypeName("uint32_t")]
public static extern uint query_start_byte_for_pattern([NativeTypeName("const TSQuery *")] TSQuery* self, [NativeTypeName("uint32_t")] uint pattern_index);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_end_byte_for_pattern", ExactSpelling = true)]
[return: NativeTypeName("uint32_t")]
public static extern uint query_end_byte_for_pattern([NativeTypeName("const TSQuery *")] TSQuery* self, [NativeTypeName("uint32_t")] uint pattern_index);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_predicates_for_pattern", ExactSpelling = true)]
[return: NativeTypeName("const TSQueryPredicateStep *")]
public static extern TSQueryPredicateStep* query_predicates_for_pattern([NativeTypeName("const TSQuery *")] TSQuery* self, [NativeTypeName("uint32_t")] uint pattern_index, [NativeTypeName("uint32_t *")] uint* step_count);
Expand Down Expand Up @@ -363,6 +374,9 @@ public static unsafe partial class TSBindingsParser
[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_exec", ExactSpelling = true)]
public static extern void query_cursor_exec(TSQueryCursor* self, [NativeTypeName("const TSQuery *")] TSQuery* query, TSNode node);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_exec_with_options", ExactSpelling = true)]
public static extern void query_cursor_exec_with_options(TSQueryCursor* self, [NativeTypeName("const TSQuery *")] TSQuery* query, TSNode node, [NativeTypeName("const TSQueryCursorOptions *")] TSQueryCursorOptions* query_options);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_did_exceed_match_limit", ExactSpelling = true)]
[return: NativeTypeName("bool")]
public static extern byte query_cursor_did_exceed_match_limit([NativeTypeName("const TSQueryCursor *")] TSQueryCursor* self);
Expand All @@ -374,11 +388,20 @@ public static unsafe partial class TSBindingsParser
[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_set_match_limit", ExactSpelling = true)]
public static extern void query_cursor_set_match_limit(TSQueryCursor* self, [NativeTypeName("uint32_t")] uint limit);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_set_timeout_micros", ExactSpelling = true)]
public static extern void query_cursor_set_timeout_micros(TSQueryCursor* self, [NativeTypeName("uint64_t")] nuint timeout_micros);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_timeout_micros", ExactSpelling = true)]
[return: NativeTypeName("uint64_t")]
public static extern nuint query_cursor_timeout_micros([NativeTypeName("const TSQueryCursor *")] TSQueryCursor* self);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_set_byte_range", ExactSpelling = true)]
public static extern void query_cursor_set_byte_range(TSQueryCursor* self, [NativeTypeName("uint32_t")] uint start_byte, [NativeTypeName("uint32_t")] uint end_byte);
[return: NativeTypeName("bool")]
public static extern byte query_cursor_set_byte_range(TSQueryCursor* self, [NativeTypeName("uint32_t")] uint start_byte, [NativeTypeName("uint32_t")] uint end_byte);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_set_point_range", ExactSpelling = true)]
public static extern void query_cursor_set_point_range(TSQueryCursor* self, TSPoint start_point, TSPoint end_point);
[return: NativeTypeName("bool")]
public static extern byte query_cursor_set_point_range(TSQueryCursor* self, TSPoint start_point, TSPoint end_point);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_query_cursor_next_match", ExactSpelling = true)]
[return: NativeTypeName("bool")]
Expand Down Expand Up @@ -409,10 +432,6 @@ public static unsafe partial class TSBindingsParser
[return: NativeTypeName("uint32_t")]
public static extern uint language_state_count([NativeTypeName("const TSLanguage *")] TSLanguage* self);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_symbol_name", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
public static extern sbyte* language_symbol_name([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("TSSymbol")] ushort symbol);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_symbol_for_name", ExactSpelling = true)]
[return: NativeTypeName("TSSymbol")]
public static extern ushort language_symbol_for_name([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("const char *")] sbyte* @string, [NativeTypeName("uint32_t")] uint length, [NativeTypeName("bool")] byte is_named);
Expand All @@ -429,17 +448,41 @@ public static unsafe partial class TSBindingsParser
[return: NativeTypeName("TSFieldId")]
public static extern ushort language_field_id_for_name([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("const char *")] sbyte* name, [NativeTypeName("uint32_t")] uint name_length);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_supertypes", ExactSpelling = true)]
[return: NativeTypeName("const TSSymbol *")]
public static extern ushort* language_supertypes([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("uint32_t *")] uint* length);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_subtypes", ExactSpelling = true)]
[return: NativeTypeName("const TSSymbol *")]
public static extern ushort* language_subtypes([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("TSSymbol")] ushort supertype, [NativeTypeName("uint32_t *")] uint* length);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_symbol_name", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
public static extern sbyte* language_symbol_name([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("TSSymbol")] ushort symbol);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_symbol_type", ExactSpelling = true)]
public static extern TSSymbolType language_symbol_type([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("TSSymbol")] ushort symbol);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_version", ExactSpelling = true)]
[return: NativeTypeName("uint32_t")]
public static extern uint language_version([NativeTypeName("const TSLanguage *")] TSLanguage* self);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_abi_version", ExactSpelling = true)]
[return: NativeTypeName("uint32_t")]
public static extern uint language_abi_version([NativeTypeName("const TSLanguage *")] TSLanguage* self);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_metadata", ExactSpelling = true)]
[return: NativeTypeName("const TSLanguageMetadata *")]
public static extern TSLanguageMetadata* language_metadata([NativeTypeName("const TSLanguage *")] TSLanguage* self);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_next_state", ExactSpelling = true)]
[return: NativeTypeName("TSStateId")]
public static extern ushort language_next_state([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("TSStateId")] ushort state, [NativeTypeName("TSSymbol")] ushort symbol);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_language_name", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
public static extern sbyte* language_name([NativeTypeName("const TSLanguage *")] TSLanguage* self);

[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_lookahead_iterator_new", ExactSpelling = true)]
public static extern TSLookaheadIterator* lookahead_iterator_new([NativeTypeName("const TSLanguage *")] TSLanguage* self, [NativeTypeName("TSStateId")] ushort state);

Expand Down Expand Up @@ -497,8 +540,8 @@ public static unsafe partial class TSBindingsParser
[DllImport("libtree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_set_allocator", ExactSpelling = true)]
public static extern void set_allocator([NativeTypeName("void *(*)(size_t)")] delegate* unmanaged[Cdecl]<nuint, void*> new_malloc, [NativeTypeName("void *(*)(size_t, size_t)")] delegate* unmanaged[Cdecl]<nuint, nuint, void*> new_calloc, [NativeTypeName("void *(*)(void *, size_t)")] delegate* unmanaged[Cdecl]<void*, nuint, void*> new_realloc, [NativeTypeName("void (*)(void *)")] delegate* unmanaged[Cdecl]<void*, void> new_free);

[NativeTypeName("#define TREE_SITTER_LANGUAGE_VERSION 14")]
public const int TREE_SITTER_LANGUAGE_VERSION = 14;
[NativeTypeName("#define TREE_SITTER_LANGUAGE_VERSION 15")]
public const int TREE_SITTER_LANGUAGE_VERSION = 15;

[NativeTypeName("#define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION 13")]
public const int TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION = 13;
Expand Down
3 changes: 3 additions & 0 deletions src/TreeSitter.Bindings/TSInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ public unsafe partial struct TSInput
public delegate* unmanaged[Cdecl]<void*, uint, TSPoint, uint*, sbyte*> read;

public TSInputEncoding encoding;

[NativeTypeName("DecodeFunction")]
public delegate* unmanaged[Cdecl]<byte*, uint, int*, uint> decode;
}
4 changes: 3 additions & 1 deletion src/TreeSitter.Bindings/TSInputEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ namespace TreeSitter.Bindings;
public enum TSInputEncoding : uint
{
TSInputEncodingUTF8,
TSInputEncodingUTF16,
TSInputEncodingUTF16LE,
TSInputEncodingUTF16BE,
TSInputEncodingCustom,
}
13 changes: 13 additions & 0 deletions src/TreeSitter.Bindings/TSLanguageMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace TreeSitter.Bindings;

public partial struct TSLanguageMetadata
{
[NativeTypeName("uint8_t")]
public byte major_version;

[NativeTypeName("uint8_t")]
public byte minor_version;

[NativeTypeName("uint8_t")]
public byte patch_version;
}
9 changes: 9 additions & 0 deletions src/TreeSitter.Bindings/TSParseOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TreeSitter.Bindings;

public unsafe partial struct TSParseOptions
{
public void* payload;

[NativeTypeName("bool (*)(TSParseState *)")]
public delegate* unmanaged[Cdecl]<TSParseState*, byte> progress_callback;
}
12 changes: 12 additions & 0 deletions src/TreeSitter.Bindings/TSParseState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace TreeSitter.Bindings;

public unsafe partial struct TSParseState
{
public void* payload;

[NativeTypeName("uint32_t")]
public uint current_byte_offset;

[NativeTypeName("bool")]
public byte has_error;
}
9 changes: 9 additions & 0 deletions src/TreeSitter.Bindings/TSQueryCursorOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TreeSitter.Bindings;

public unsafe partial struct TSQueryCursorOptions
{
public void* payload;

[NativeTypeName("bool (*)(TSQueryCursorState *)")]
public delegate* unmanaged[Cdecl]<TSQueryCursorState*, byte> progress_callback;
}
9 changes: 9 additions & 0 deletions src/TreeSitter.Bindings/TSQueryCursorState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TreeSitter.Bindings;

public unsafe partial struct TSQueryCursorState
{
public void* payload;

[NativeTypeName("uint32_t")]
public uint current_byte_offset;
}
1 change: 1 addition & 0 deletions src/TreeSitter.Bindings/TSSymbolType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum TSSymbolType : uint
{
TSSymbolTypeRegular,
TSSymbolTypeAnonymous,
TSSymbolTypeSupertype,
TSSymbolTypeAuxiliary,
}
4 changes: 2 additions & 2 deletions tests/TreeSitter.Bindings.UnitTests/TSInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public static void SizeOfTest()
{
if (Environment.Is64BitProcess)
{
Assert.Equal(24, sizeof(TSInput));
Assert.Equal(32, sizeof(TSInput));
}
else
{
Assert.Equal(12, sizeof(TSInput));
Assert.Equal(16, sizeof(TSInput));
}
}
}
29 changes: 29 additions & 0 deletions tests/TreeSitter.Bindings.UnitTests/TSLanguageMetadataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Runtime.InteropServices;
using Xunit;

namespace TreeSitter.Bindings.UnitTests;

/// <summary>Provides validation of the <see cref="TSLanguageMetadata" /> struct.</summary>
public static unsafe partial class TSLanguageMetadataTests
{
/// <summary>Validates that the <see cref="TSLanguageMetadata" /> struct is blittable.</summary>
[Fact]
public static void IsBlittableTest()
{
Assert.Equal(sizeof(TSLanguageMetadata), Marshal.SizeOf<TSLanguageMetadata>());
}

/// <summary>Validates that the <see cref="TSLanguageMetadata" /> struct has the right <see cref="LayoutKind" />.</summary>
[Fact]
public static void IsLayoutSequentialTest()
{
Assert.True(typeof(TSLanguageMetadata).IsLayoutSequential);
}

/// <summary>Validates that the <see cref="TSLanguageMetadata" /> struct has the correct size.</summary>
[Fact]
public static void SizeOfTest()
{
Assert.Equal(3, sizeof(TSLanguageMetadata));
}
}
37 changes: 37 additions & 0 deletions tests/TreeSitter.Bindings.UnitTests/TSParseOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;
using Xunit;

namespace TreeSitter.Bindings.UnitTests;

/// <summary>Provides validation of the <see cref="TSParseOptions" /> struct.</summary>
public static unsafe partial class TSParseOptionsTests
{
/// <summary>Validates that the <see cref="TSParseOptions" /> struct is blittable.</summary>
[Fact]
public static void IsBlittableTest()
{
Assert.Equal(sizeof(TSParseOptions), Marshal.SizeOf<TSParseOptions>());
}

/// <summary>Validates that the <see cref="TSParseOptions" /> struct has the right <see cref="LayoutKind" />.</summary>
[Fact]
public static void IsLayoutSequentialTest()
{
Assert.True(typeof(TSParseOptions).IsLayoutSequential);
}

/// <summary>Validates that the <see cref="TSParseOptions" /> struct has the correct size.</summary>
[Fact]
public static void SizeOfTest()
{
if (Environment.Is64BitProcess)
{
Assert.Equal(16, sizeof(TSParseOptions));
}
else
{
Assert.Equal(8, sizeof(TSParseOptions));
}
}
}
37 changes: 37 additions & 0 deletions tests/TreeSitter.Bindings.UnitTests/TSParseStateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;
using Xunit;

namespace TreeSitter.Bindings.UnitTests;

/// <summary>Provides validation of the <see cref="TSParseState" /> struct.</summary>
public static unsafe partial class TSParseStateTests
{
/// <summary>Validates that the <see cref="TSParseState" /> struct is blittable.</summary>
[Fact]
public static void IsBlittableTest()
{
Assert.Equal(sizeof(TSParseState), Marshal.SizeOf<TSParseState>());
}

/// <summary>Validates that the <see cref="TSParseState" /> struct has the right <see cref="LayoutKind" />.</summary>
[Fact]
public static void IsLayoutSequentialTest()
{
Assert.True(typeof(TSParseState).IsLayoutSequential);
}

/// <summary>Validates that the <see cref="TSParseState" /> struct has the correct size.</summary>
[Fact]
public static void SizeOfTest()
{
if (Environment.Is64BitProcess)
{
Assert.Equal(16, sizeof(TSParseState));
}
else
{
Assert.Equal(12, sizeof(TSParseState));
}
}
}
Loading

0 comments on commit 368f5db

Please sign in to comment.