From 06a4f54555be4d0eb0efa766eea824325df6fee1 Mon Sep 17 00:00:00 2001 From: Summpot Date: Fri, 3 Nov 2023 18:18:31 +0800 Subject: [PATCH] Update --- src/TreeSitterSharp.C/CParser.cs | 2 +- src/TreeSitterSharp.Json/JsonParser.cs | 2 +- ...eeSitterSyntaxParser.cs => TreeSitterParser.cs} | 6 +++--- .../{QueryCursor.cs => TreeSitterQueryCursor.cs} | 4 ++-- src/TreeSitterSharp/TreeSitterSharp.csproj | 1 - src/TreeSitterSharp/TreeSitterSyntaxTree.cs | 2 -- ...TreeCursor.cs => TreeSitterSyntaxTreeCursor.cs} | 14 +++++++------- tests/TreeSitterSharp.C.Tests/CParserTests.cs | 4 ++-- 8 files changed, 16 insertions(+), 19 deletions(-) rename src/TreeSitterSharp/{TreeSitterSyntaxParser.cs => TreeSitterParser.cs} (92%) rename src/TreeSitterSharp/{QueryCursor.cs => TreeSitterQueryCursor.cs} (93%) rename src/TreeSitterSharp/{SyntaxTreeCursor.cs => TreeSitterSyntaxTreeCursor.cs} (80%) diff --git a/src/TreeSitterSharp.C/CParser.cs b/src/TreeSitterSharp.C/CParser.cs index 3d0b8c8..2114866 100644 --- a/src/TreeSitterSharp.C/CParser.cs +++ b/src/TreeSitterSharp.C/CParser.cs @@ -1,5 +1,5 @@ namespace TreeSitterSharp.C; -public class CParser : TreeSitterSyntaxParser +public class CParser : TreeSitterParser { public CParser() : base(CLanguageProvider.GetLanguage()) { diff --git a/src/TreeSitterSharp.Json/JsonParser.cs b/src/TreeSitterSharp.Json/JsonParser.cs index ce6c67e..ec432ba 100644 --- a/src/TreeSitterSharp.Json/JsonParser.cs +++ b/src/TreeSitterSharp.Json/JsonParser.cs @@ -1,6 +1,6 @@  namespace TreeSitterSharp.Json; -public class JsonParser : TreeSitterSyntaxParser +public class JsonParser : TreeSitterParser { public JsonParser() : base(JsonLanguageProvider.GetLanguage()) { diff --git a/src/TreeSitterSharp/TreeSitterSyntaxParser.cs b/src/TreeSitterSharp/TreeSitterParser.cs similarity index 92% rename from src/TreeSitterSharp/TreeSitterSyntaxParser.cs rename to src/TreeSitterSharp/TreeSitterParser.cs index 101170b..cb0f00d 100644 --- a/src/TreeSitterSharp/TreeSitterSyntaxParser.cs +++ b/src/TreeSitterSharp/TreeSitterParser.cs @@ -3,14 +3,14 @@ using TreeSitterSharp.Native; namespace TreeSitterSharp; -public unsafe class TreeSitterSyntaxParser : INativeObject +public unsafe class TreeSitterParser : INativeObject { private TsParser* _parser; private Language? _language; - public TreeSitterSyntaxParser(Language language) + public TreeSitterParser(Language language) { static void* NewMalloc(nuint byteCount) => NativeMemory.Alloc(byteCount); static void* NewCalloc(nuint count, nuint size) => NativeMemory.AllocZeroed(count * size); @@ -21,7 +21,7 @@ public TreeSitterSyntaxParser(Language language) Language = language; } - ~TreeSitterSyntaxParser() + ~TreeSitterParser() { Ts.parser_delete(_parser); } diff --git a/src/TreeSitterSharp/QueryCursor.cs b/src/TreeSitterSharp/TreeSitterQueryCursor.cs similarity index 93% rename from src/TreeSitterSharp/QueryCursor.cs rename to src/TreeSitterSharp/TreeSitterQueryCursor.cs index a927be8..b5f6ae6 100644 --- a/src/TreeSitterSharp/QueryCursor.cs +++ b/src/TreeSitterSharp/TreeSitterQueryCursor.cs @@ -9,11 +9,11 @@ namespace TreeSitterSharp; -public unsafe class QueryCursor +public unsafe class TreeSitterQueryCursor { private TsQueryCursor* _queryCursor; - public QueryCursor() + public TreeSitterQueryCursor() { _queryCursor = Ts.query_cursor_new(); } diff --git a/src/TreeSitterSharp/TreeSitterSharp.csproj b/src/TreeSitterSharp/TreeSitterSharp.csproj index 8f33c87..fef6d2c 100644 --- a/src/TreeSitterSharp/TreeSitterSharp.csproj +++ b/src/TreeSitterSharp/TreeSitterSharp.csproj @@ -9,7 +9,6 @@ preview - diff --git a/src/TreeSitterSharp/TreeSitterSyntaxTree.cs b/src/TreeSitterSharp/TreeSitterSyntaxTree.cs index f8c2ad6..bfd673a 100644 --- a/src/TreeSitterSharp/TreeSitterSyntaxTree.cs +++ b/src/TreeSitterSharp/TreeSitterSyntaxTree.cs @@ -1,6 +1,4 @@ using System.Text; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Text; using TreeSitterSharp.Native; namespace TreeSitterSharp; diff --git a/src/TreeSitterSharp/SyntaxTreeCursor.cs b/src/TreeSitterSharp/TreeSitterSyntaxTreeCursor.cs similarity index 80% rename from src/TreeSitterSharp/SyntaxTreeCursor.cs rename to src/TreeSitterSharp/TreeSitterSyntaxTreeCursor.cs index cbbeff1..cccd37e 100644 --- a/src/TreeSitterSharp/SyntaxTreeCursor.cs +++ b/src/TreeSitterSharp/TreeSitterSyntaxTreeCursor.cs @@ -1,20 +1,20 @@ using TreeSitterSharp.Native; namespace TreeSitterSharp; -public class SyntaxTreeCursor +public class TreeSitterSyntaxTreeCursor { private readonly TsTreeCursor _treeCursor; private readonly TsNode _node; - public SyntaxTreeCursor(TreeSitterSyntaxNode node) + public TreeSitterSyntaxTreeCursor(TreeSitterSyntaxNode node) { _node = node.ToUnmanaged(); _treeCursor = Ts.tree_cursor_new(_node); } - private SyntaxTreeCursor(TsTreeCursor treeCursor) => _treeCursor = treeCursor; + private TreeSitterSyntaxTreeCursor(TsTreeCursor treeCursor) => _treeCursor = treeCursor; - ~SyntaxTreeCursor() + ~TreeSitterSyntaxTreeCursor() { Ts.tree_cursor_delete(_treeCursor); } @@ -39,13 +39,13 @@ public void Reset() Ts.tree_cursor_reset(_treeCursor, _node); } - public void ResetTo(SyntaxTreeCursor dst) + public void ResetTo(TreeSitterSyntaxTreeCursor dst) { Ts.tree_cursor_reset_to(dst._treeCursor, _treeCursor); } - public SyntaxTreeCursor Copy() + public TreeSitterSyntaxTreeCursor Copy() { - return new SyntaxTreeCursor(Ts.tree_cursor_copy(_treeCursor)); + return new TreeSitterSyntaxTreeCursor(Ts.tree_cursor_copy(_treeCursor)); } } diff --git a/tests/TreeSitterSharp.C.Tests/CParserTests.cs b/tests/TreeSitterSharp.C.Tests/CParserTests.cs index 41b4a1e..adfbf9a 100644 --- a/tests/TreeSitterSharp.C.Tests/CParserTests.cs +++ b/tests/TreeSitterSharp.C.Tests/CParserTests.cs @@ -26,7 +26,7 @@ int fibonacci(int n) { var tree = parser.Parse(code); - var treeCursor = new SyntaxTreeCursor(tree.Root); + var treeCursor = new TreeSitterSyntaxTreeCursor(tree.Root); var a = treeCursor.GotoFirstChild(); Assert.Equal(expected, tree.Root.GetSExpression()); } @@ -51,7 +51,7 @@ int fibonacci(int n) { var tree = parser.Parse(code); - var cursor = new QueryCursor(); + var cursor = new TreeSitterQueryCursor(); cursor.Execute(Query.Create(tree.Language, "(preproc_include)", out var errorOffset, out var error), tree.Root);