Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Summpot committed Oct 30, 2023
1 parent f2e1bf4 commit d32d270
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 235 deletions.
6 changes: 3 additions & 3 deletions src/TreeSitterSharp.C/CLanguageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace TreeSitterSharp.C;
internal class CLanguageProvider : ILanguageProvider
{
[DllImport("tree-sitter-c", EntryPoint = "tree_sitter_c", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern unsafe TsLanguage* tree_sitter_c();
private static extern unsafe Native.TsLanguage* tree_sitter_c();

public static unsafe Language GetLanguage()
public static unsafe TsLanguage GetLanguage()
{
return new Language(tree_sitter_c());
return new TsLanguage(tree_sitter_c());
}

}
2 changes: 1 addition & 1 deletion src/TreeSitterSharp.C/CParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;

namespace TreeSitterSharp.C;
public class CParser : Parser
public class CParser : TsParser
{
public CParser() : base(CLanguageProvider.GetLanguage())
{
Expand Down
4 changes: 2 additions & 2 deletions src/TreeSitterSharp.Json/JsonLanguageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace TreeSitterSharp.Json
internal unsafe class JsonLanguageProvider : ILanguageProvider
{
[DllImport("tree-sitter-json", EntryPoint = "tree_sitter_json", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern unsafe TsLanguage* tree_sitter_json();
private static extern unsafe Native.TsLanguage* tree_sitter_json();

public static Language GetLanguage() => new(tree_sitter_json());
public static TsLanguage GetLanguage() => new(tree_sitter_json());
}
}
2 changes: 1 addition & 1 deletion src/TreeSitterSharp.Json/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;

namespace TreeSitterSharp.Json;
public class JsonParser : Parser
public class JsonParser : TsParser
{
public JsonParser() : base(JsonLanguageProvider.GetLanguage())
{
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/ILanguageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
namespace TreeSitterSharp;
public interface ILanguageProvider
{
static abstract Language GetLanguage();
static abstract TsLanguage GetLanguage();
}
32 changes: 13 additions & 19 deletions src/TreeSitterSharp/Native/Ts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ public static extern void
[return: NativeTypeName("const TsLanguage *")]
public static extern TsLanguage* node_language(TsNode self);

[DllImport("tree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_grammar_type",
ExactSpelling = true)]
[return: NativeTypeName("const char *")]
public static extern string node_grammar_type(TsNode self);
[LibraryImport("tree-sitter", EntryPoint = "ts_node_grammar_type", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(ConstantStringMarshaller))]
public static partial string node_grammar_type(TsNode self);

[DllImport("tree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_grammar_symbol",
ExactSpelling = true)]
Expand Down Expand Up @@ -171,21 +169,18 @@ public static extern void
StringMarshallingCustomType = typeof(StringMarshaller))]
public static partial string node_string(TsNode self);

[LibraryImport("tree-sitter", EntryPoint = "ts_node_is_null")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool node_is_null(TsNode self);
[DllImport("tree-sitter", EntryPoint = "ts_node_is_null")]
public static extern bool node_is_null(TsNode self);

[LibraryImport("tree-sitter", EntryPoint = "ts_node_is_named")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool node_is_named(TsNode self);
[DllImport("tree-sitter", EntryPoint = "ts_node_is_named")]
public static extern bool node_is_named(TsNode self);

[LibraryImport("tree-sitter", EntryPoint = "ts_node_is_missing")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool node_is_missing(TsNode self);
[DllImport("tree-sitter", EntryPoint = "ts_node_is_missing")]
public static extern bool node_is_missing(TsNode self);

[LibraryImport("tree-sitter", EntryPoint = "ts_node_is_extra")]
[DllImport("tree-sitter", EntryPoint = "ts_node_is_extra")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool node_is_extra(TsNode self);
public static extern bool node_is_extra(TsNode self);

[DllImport("tree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_has_changes",
ExactSpelling = true)]
Expand Down Expand Up @@ -220,10 +215,9 @@ public static extern void
ExactSpelling = true)]
public static extern TsNode node_child(TsNode self, [NativeTypeName("uint32_t")] uint child_index);

[DllImport("tree-sitter", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "ts_node_field_name_for_child", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
public static extern string node_field_name_for_child(TsNode self, [NativeTypeName("uint32_t")] uint child_index);
[LibraryImport("tree-sitter", EntryPoint = "ts_node_field_name_for_child", StringMarshalling = StringMarshalling.Custom,
StringMarshallingCustomType = typeof(StringMarshaller))]
public static partial string node_field_name_for_child(TsNode self, [NativeTypeName("uint32_t")] uint child_index);

[DllImport("tree-sitter", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts_node_child_count",
ExactSpelling = true)]
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public unsafe partial struct TsInput
{
public void* payload;

[NativeTypeName("const char *(*)(void *, uint32_t, TsPoint, uint32_t *)")]
[NativeTypeName("const char *(*)(void *, uint32_t, TSPoint, uint32_t *)")]
public delegate* unmanaged[Cdecl]<void*, uint, TsPoint, uint*, string> read;

public TsInputEncoding encoding;
Expand Down
13 changes: 0 additions & 13 deletions src/TreeSitterSharp/Native/TsPoint.cs

This file was deleted.

136 changes: 0 additions & 136 deletions src/TreeSitterSharp/Node.cs

This file was deleted.

7 changes: 7 additions & 0 deletions src/TreeSitterSharp/TSPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TreeSitterSharp;
public struct TsPoint
{
public uint Row;

public uint Column;
}
28 changes: 0 additions & 28 deletions src/TreeSitterSharp/Tree.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
using TreeSitterSharp.Native;

namespace TreeSitterSharp;
public unsafe class Language
public unsafe class TsLanguage
{
private TsLanguage* _language;
private Native.TsLanguage* _language;

public Language(TsLanguage* language)
public TsLanguage(Native.TsLanguage* language)
{
_language = language;
}

public TsLanguage* ToUnmanaged()
public Native.TsLanguage* ToUnmanaged()
{
return _language;
}
Expand Down
Loading

0 comments on commit d32d270

Please sign in to comment.