Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Summpot committed Nov 1, 2023
1 parent d32d270 commit a07b842
Show file tree
Hide file tree
Showing 43 changed files with 266 additions and 232 deletions.
13 changes: 4 additions & 9 deletions src/TreeSitterSharp.C/CLanguageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using TreeSitterSharp.Native;

namespace TreeSitterSharp.C;
internal class CLanguageProvider : ILanguageProvider
{
[DllImport("tree-sitter-c", EntryPoint = "tree_sitter_c", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern unsafe Native.TsLanguage* tree_sitter_c();
private static extern unsafe TsLanguage* tree_sitter_c();

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

}
10 changes: 2 additions & 8 deletions src/TreeSitterSharp.C/CParser.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TreeSitterSharp.C;
public class CParser : TsParser
namespace TreeSitterSharp.C;
public class CParser : Parser
{
public CParser() : base(CLanguageProvider.GetLanguage())
{
Expand Down
11 changes: 3 additions & 8 deletions src/TreeSitterSharp.Json/JsonLanguageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using TreeSitterSharp.Native;

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 Native.TsLanguage* tree_sitter_json();
private static extern TsLanguage* tree_sitter_json();

public static TsLanguage GetLanguage() => new(tree_sitter_json());
public static Language GetLanguage() => new(tree_sitter_json());
}
}
8 changes: 1 addition & 7 deletions src/TreeSitterSharp.Json/JsonParser.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TreeSitterSharp.Json;
public class JsonParser : TsParser
public class JsonParser : Parser
{
public JsonParser() : base(JsonLanguageProvider.GetLanguage())
{
Expand Down
10 changes: 2 additions & 8 deletions src/TreeSitterSharp/ILanguageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TreeSitterSharp;
namespace TreeSitterSharp;
public interface ILanguageProvider
{
static abstract TsLanguage GetLanguage();
static abstract Language GetLanguage();
}
11 changes: 11 additions & 0 deletions src/TreeSitterSharp/INativeObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TreeSitterSharp;
internal interface INativeObject<T> where T : struct
{
unsafe T* ToUnmanaged();
}
17 changes: 17 additions & 0 deletions src/TreeSitterSharp/Language.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using TreeSitterSharp.Native;

namespace TreeSitterSharp;
public unsafe class Language:INativeObject<TsLanguage>
{
private TsLanguage* _language;

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

public TsLanguage* ToUnmanaged()
{
return _language;
}
}
5 changes: 2 additions & 3 deletions src/TreeSitterSharp/Native/NativeTypeNameAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Diagnostics;

namespace TreeSitterSharp.Native;

/// <summary>Defines the type of a member as it was used in the native signature.</summary>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)]
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
[Conditional("DEBUG")]
internal sealed partial class NativeTypeNameAttribute : Attribute
internal sealed class NativeTypeNameAttribute : Attribute
{
private readonly string _name;

Expand Down
66 changes: 33 additions & 33 deletions src/TreeSitterSharp/Native/Ts.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsFieldMapEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public partial struct TsFieldMapEntry
public struct TsFieldMapEntry
{
[NativeTypeName("TSFieldId")]
public ushort field_id;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsFieldMapSlice.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public partial struct TsFieldMapSlice
public struct TsFieldMapSlice
{
[NativeTypeName("uint16_t")]
public ushort index;
Expand Down
4 changes: 2 additions & 2 deletions src/TreeSitterSharp/Native/TsInput.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace TreeSitterSharp.Native;

public unsafe partial struct TsInput
public unsafe struct TsInput
{
public void* payload;

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

public TsInputEncoding encoding;
}
8 changes: 4 additions & 4 deletions src/TreeSitterSharp/Native/TsInputEdit.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public partial struct TsInputEdit
public struct TsInputEdit
{
[NativeTypeName("uint32_t")]
public uint start_byte;
Expand All @@ -11,9 +11,9 @@ public partial struct TsInputEdit
[NativeTypeName("uint32_t")]
public uint new_end_byte;

public TsPoint start_point;
public Point start_point;

public TsPoint old_end_point;
public Point old_end_point;

public TsPoint new_end_point;
public Point new_end_point;
}
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public unsafe partial struct TsLanguage
[NativeTypeName("const TSStateId *")]
public ushort* primary_state_ids;

public unsafe partial struct _external_scanner_e__Struct
public struct _external_scanner_e__Struct
{
[NativeTypeName("const bool *")]
public bool* states;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsLexMode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public partial struct TsLexMode
public struct TsLexMode
{
[NativeTypeName("uint16_t")]
public ushort lex_state;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsLexer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public unsafe partial struct TsLexer
public unsafe struct TsLexer
{
[NativeTypeName("int32_t")]
public int lookahead;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsLogger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public unsafe partial struct TsLogger
public unsafe struct TsLogger
{
public void* payload;

Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsLookaheadIterator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace TreeSitterSharp.Native;

public partial struct TsLookaheadIterator
public struct TsLookaheadIterator
{
}
4 changes: 2 additions & 2 deletions src/TreeSitterSharp/Native/TsNode.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace TreeSitterSharp.Native;

public unsafe partial struct TsNode
public unsafe struct TsNode
{
[NativeTypeName("uint32_t[4]")]
public fixed uint context[4];

[NativeTypeName("const void *")]
public void* id;

[NativeTypeName("const TsTree *")]
[NativeTypeName("const Tree *")]
public TsTree* tree;
}
4 changes: 2 additions & 2 deletions src/TreeSitterSharp/Native/TsParseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial struct TsParseAction
[NativeTypeName("uint8_t")]
public byte type;

public partial struct _shift_e__Struct
public struct _shift_e__Struct
{
[NativeTypeName("uint8_t")]
public byte type;
Expand All @@ -32,7 +32,7 @@ public partial struct _shift_e__Struct
public byte repetition;
}

public partial struct _reduce_e__Struct
public struct _reduce_e__Struct
{
[NativeTypeName("uint8_t")]
public byte type;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsParseActionEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial struct TsParseActionEntry
[NativeTypeName("__AnonymousRecord_parser_L83_C3")]
public EntryEStruct entry;

public partial struct EntryEStruct
public struct EntryEStruct
{
[NativeTypeName("uint8_t")]
public byte Count;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace TreeSitterSharp.Native;

public partial struct TsParser
public struct TsParser
{
}
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsQuery.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace TreeSitterSharp.Native;

public partial struct TsQuery
public struct TsQuery
{
}
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsQueryCapture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public partial struct TsQueryCapture
public struct TsQueryCapture
{
public TsNode Node;

Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsQueryCursor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace TreeSitterSharp.Native;

public partial struct TsQueryCursor
public struct TsQueryCursor
{
}
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsQueryMatch.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public unsafe partial struct TsQueryMatch
public unsafe struct TsQueryMatch
{
[NativeTypeName("uint32_t")]
public uint Id;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsQueryPredicateStep.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public partial struct TsQueryPredicateStep
public struct TsQueryPredicateStep
{
public TsQueryPredicateStepType Type;

Expand Down
6 changes: 3 additions & 3 deletions src/TreeSitterSharp/Native/TsRange.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace TreeSitterSharp.Native;

public partial struct TsRange
public struct TsRange
{
public TsPoint start_point;
public Point start_point;

public TsPoint end_point;
public Point end_point;

public uint start_byte;

Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsSymbolMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public partial struct TsSymbolMetadata
public struct TsSymbolMetadata
{
[NativeTypeName("bool")]
public byte Visible;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp/Native/TsTreeCursor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TreeSitterSharp.Native;

public unsafe partial struct TsTreeCursor
public unsafe struct TsTreeCursor
{
public TsTree* tree;

Expand Down
Loading

0 comments on commit a07b842

Please sign in to comment.