Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Summpot committed Nov 3, 2023
1 parent acae31a commit 06a4f54
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/TreeSitterSharp.C/CParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace TreeSitterSharp.C;
public class CParser : TreeSitterSyntaxParser
public class CParser : TreeSitterParser
{
public CParser() : base(CLanguageProvider.GetLanguage())
{
Expand Down
2 changes: 1 addition & 1 deletion src/TreeSitterSharp.Json/JsonParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

namespace TreeSitterSharp.Json;
public class JsonParser : TreeSitterSyntaxParser
public class JsonParser : TreeSitterParser
{
public JsonParser() : base(JsonLanguageProvider.GetLanguage())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
using TreeSitterSharp.Native;

namespace TreeSitterSharp;
public unsafe class TreeSitterSyntaxParser : INativeObject<TsParser>
public unsafe class TreeSitterParser : INativeObject<TsParser>
{
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);
Expand All @@ -21,7 +21,7 @@ public TreeSitterSyntaxParser(Language language)
Language = language;
}

~TreeSitterSyntaxParser()
~TreeSitterParser()
{
Ts.parser_delete(_parser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion src/TreeSitterSharp/TreeSitterSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.7.0" />
<PackageReference Include="tree-sitter" Version="*" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions src/TreeSitterSharp/TreeSitterSyntaxTree.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using TreeSitterSharp.Native;

namespace TreeSitterSharp;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Expand All @@ -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));
}
}
4 changes: 2 additions & 2 deletions tests/TreeSitterSharp.C.Tests/CParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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);

Expand Down

0 comments on commit 06a4f54

Please sign in to comment.