From d32d27015f809013d69b46d5d8c61e7b3e2308c7 Mon Sep 17 00:00:00 2001 From: Summpot Date: Mon, 30 Oct 2023 22:09:32 +0800 Subject: [PATCH] Update --- src/TreeSitterSharp.C/CLanguageProvider.cs | 6 +- src/TreeSitterSharp.C/CParser.cs | 2 +- .../JsonLanguageProvider.cs | 4 +- src/TreeSitterSharp.Json/JsonParser.cs | 2 +- src/TreeSitterSharp/ILanguageProvider.cs | 2 +- src/TreeSitterSharp/Native/Ts.cs | 32 ++-- src/TreeSitterSharp/Native/TsInput.cs | 2 +- src/TreeSitterSharp/Native/TsPoint.cs | 13 -- src/TreeSitterSharp/Node.cs | 136 ---------------- src/TreeSitterSharp/TSPoint.cs | 7 + src/TreeSitterSharp/Tree.cs | 28 ---- .../{Language.cs => TsLanguage.cs} | 8 +- src/TreeSitterSharp/TsNode.cs | 146 ++++++++++++++++++ .../{Parser.cs => TsParser.cs} | 20 +-- src/TreeSitterSharp/TsTree.cs | 28 ++++ .../{TreeCursor.cs => TsTreeCursor.cs} | 20 +-- tests/TreeSitterSharp.C.Tests/CParserTests.cs | 3 +- .../JsonParserTests.cs | 8 +- 18 files changed, 232 insertions(+), 235 deletions(-) delete mode 100644 src/TreeSitterSharp/Native/TsPoint.cs delete mode 100644 src/TreeSitterSharp/Node.cs create mode 100644 src/TreeSitterSharp/TSPoint.cs delete mode 100644 src/TreeSitterSharp/Tree.cs rename src/TreeSitterSharp/{Language.cs => TsLanguage.cs} (61%) create mode 100644 src/TreeSitterSharp/TsNode.cs rename src/TreeSitterSharp/{Parser.cs => TsParser.cs} (72%) create mode 100644 src/TreeSitterSharp/TsTree.cs rename src/TreeSitterSharp/{TreeCursor.cs => TsTreeCursor.cs} (75%) diff --git a/src/TreeSitterSharp.C/CLanguageProvider.cs b/src/TreeSitterSharp.C/CLanguageProvider.cs index b899007..4f2cc72 100644 --- a/src/TreeSitterSharp.C/CLanguageProvider.cs +++ b/src/TreeSitterSharp.C/CLanguageProvider.cs @@ -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()); } } diff --git a/src/TreeSitterSharp.C/CParser.cs b/src/TreeSitterSharp.C/CParser.cs index d560755..072dab0 100644 --- a/src/TreeSitterSharp.C/CParser.cs +++ b/src/TreeSitterSharp.C/CParser.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; namespace TreeSitterSharp.C; -public class CParser : Parser +public class CParser : TsParser { public CParser() : base(CLanguageProvider.GetLanguage()) { diff --git a/src/TreeSitterSharp.Json/JsonLanguageProvider.cs b/src/TreeSitterSharp.Json/JsonLanguageProvider.cs index 1b1fdba..f16367c 100644 --- a/src/TreeSitterSharp.Json/JsonLanguageProvider.cs +++ b/src/TreeSitterSharp.Json/JsonLanguageProvider.cs @@ -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()); } } diff --git a/src/TreeSitterSharp.Json/JsonParser.cs b/src/TreeSitterSharp.Json/JsonParser.cs index 764381a..637e767 100644 --- a/src/TreeSitterSharp.Json/JsonParser.cs +++ b/src/TreeSitterSharp.Json/JsonParser.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace TreeSitterSharp.Json; -public class JsonParser : Parser +public class JsonParser : TsParser { public JsonParser() : base(JsonLanguageProvider.GetLanguage()) { diff --git a/src/TreeSitterSharp/ILanguageProvider.cs b/src/TreeSitterSharp/ILanguageProvider.cs index 55e89c2..db50d14 100644 --- a/src/TreeSitterSharp/ILanguageProvider.cs +++ b/src/TreeSitterSharp/ILanguageProvider.cs @@ -7,5 +7,5 @@ namespace TreeSitterSharp; public interface ILanguageProvider { - static abstract Language GetLanguage(); + static abstract TsLanguage GetLanguage(); } diff --git a/src/TreeSitterSharp/Native/Ts.cs b/src/TreeSitterSharp/Native/Ts.cs index ef6b78b..d603b75 100644 --- a/src/TreeSitterSharp/Native/Ts.cs +++ b/src/TreeSitterSharp/Native/Ts.cs @@ -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)] @@ -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)] @@ -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)] diff --git a/src/TreeSitterSharp/Native/TsInput.cs b/src/TreeSitterSharp/Native/TsInput.cs index 47bf626..1130deb 100644 --- a/src/TreeSitterSharp/Native/TsInput.cs +++ b/src/TreeSitterSharp/Native/TsInput.cs @@ -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] read; public TsInputEncoding encoding; diff --git a/src/TreeSitterSharp/Native/TsPoint.cs b/src/TreeSitterSharp/Native/TsPoint.cs deleted file mode 100644 index 8c3024b..0000000 --- a/src/TreeSitterSharp/Native/TsPoint.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.InteropServices; - -namespace TreeSitterSharp.Native; - -[StructLayout(LayoutKind.Sequential)] -public struct TsPoint -{ - [NativeTypeName("uint32_t")] - public uint Row; - - [NativeTypeName("uint32_t")] - public uint Column; -} diff --git a/src/TreeSitterSharp/Node.cs b/src/TreeSitterSharp/Node.cs deleted file mode 100644 index 25d7a68..0000000 --- a/src/TreeSitterSharp/Node.cs +++ /dev/null @@ -1,136 +0,0 @@ -using TreeSitterSharp.Native; - -namespace TreeSitterSharp; -public unsafe class Node -{ - private readonly TsNode _node; - - internal Node(TsNode node) - { - _node = node; - Tree = new Tree(_node.tree); - } - - public Tree Tree { get; } - public string Type => IsNull() ? "null" : Ts.node_type(_node); - public uint ChildCount => IsNull() ? 0 : Ts.node_child_count(_node); - public uint NamedChildCount => IsNull() ? 0 : Ts.node_named_child_count(_node); - public Node? PreviousSibling - { - get - { - var node = new Node(Ts.node_prev_sibling(_node)); - return node.IsNull() ? null : node; - } - } - - public Node? NextSibling - { - get - { - var node = new Node(Ts.node_next_sibling(_node)); - return node.IsNull() ? null : node; - } - } - - public Node? PreviousNamedSibling - { - get - { - var node = new Node(Ts.node_prev_named_sibling(_node)); - return node.IsNull() ? null : node; - } - } - - public Node? NextNamedSibling - { - get - { - var node = new Node(Ts.node_next_named_sibling(_node)); - return node.IsNull() ? null : node; - } - } - - public Node? Parent - { - get - { - var node = new Node(Ts.node_parent(_node)); - return node.IsNull() ? null : node; - } - } - - public bool IsNamed => !IsNull() && Ts.node_is_named(_node); - public bool IsMissing => !IsNull() && Ts.node_is_missing(_node); - public bool IsExtra => !IsNull() && Ts.node_is_extra(_node); - - public Node GetNamedChild(uint index) - { - return new Node(Ts.node_named_child(_node, index)); - } - - public IEnumerable GetNamedChildren() - { - for (uint i = 0; i < NamedChildCount; i++) - { - yield return GetNamedChild(i); - } - } - - public IEnumerable GetChildren() - { - for (uint i = 0; i < ChildCount; i++) - { - yield return GetChild(i); - } - } - - public Node GetChildByFieldName(string fieldName) - { - return new Node(Ts.node_child_by_field_name(_node, fieldName, (uint)fieldName.Length)); - } - - public Node GetChild(uint index) - { - return new Node(Ts.node_child(_node, index)); - } - - public TsNode ToUnmanaged() - { - return _node; - } - - public string GetSExpression() - { - return Ts.node_string(_node); - } - - private bool IsNull() - { - return Ts.node_is_null(_node); - } - - protected bool Equals(Node other) => Ts.node_eq(_node, other._node); - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - if (obj.GetType() != this.GetType()) - { - return false; - } - - return Equals((Node)obj); - } - - public override int GetHashCode() => _node.GetHashCode(); -} diff --git a/src/TreeSitterSharp/TSPoint.cs b/src/TreeSitterSharp/TSPoint.cs new file mode 100644 index 0000000..7515b65 --- /dev/null +++ b/src/TreeSitterSharp/TSPoint.cs @@ -0,0 +1,7 @@ +namespace TreeSitterSharp; +public struct TsPoint +{ + public uint Row; + + public uint Column; +} diff --git a/src/TreeSitterSharp/Tree.cs b/src/TreeSitterSharp/Tree.cs deleted file mode 100644 index b97bc9f..0000000 --- a/src/TreeSitterSharp/Tree.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TreeSitterSharp.Native; - -namespace TreeSitterSharp; -public unsafe class Tree -{ - private readonly TsTree* _tree; - - public Tree(TsTree* tree) - { - _tree = tree; - } - - ~Tree() - { - Ts.tree_delete(_tree); - } - - public Tree Copy() => new(Ts.tree_copy(_tree)); - - public Language Language => new(Ts.tree_language(_tree)); - - public Node Root => new(Ts.tree_root_node(_tree)); -} diff --git a/src/TreeSitterSharp/Language.cs b/src/TreeSitterSharp/TsLanguage.cs similarity index 61% rename from src/TreeSitterSharp/Language.cs rename to src/TreeSitterSharp/TsLanguage.cs index fd03a86..019a07e 100644 --- a/src/TreeSitterSharp/Language.cs +++ b/src/TreeSitterSharp/TsLanguage.cs @@ -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; } diff --git a/src/TreeSitterSharp/TsNode.cs b/src/TreeSitterSharp/TsNode.cs new file mode 100644 index 0000000..bd255fc --- /dev/null +++ b/src/TreeSitterSharp/TsNode.cs @@ -0,0 +1,146 @@ +using System.Diagnostics; +using TreeSitterSharp.Native; + +namespace TreeSitterSharp; +public unsafe class TsNode +{ + private readonly Native.TsNode _node; + + internal TsNode(Native.TsNode node) + { + _node = node; + Tree = new TsTree(_node.tree); + } + + public TsTree Tree { get; } + public nint Id => (nint)_node.id; + public string Type => Ts.node_type(_node); + public ushort Symbol => Ts.node_symbol(_node); + public TsLanguage Language => new(Ts.node_language(_node)); + public string GrammarType => Ts.node_grammar_type(_node); + public ushort GrammarSymbol => Ts.node_grammar_symbol(_node); + public uint StartByte => Ts.node_start_byte(_node); + public uint EndByte => Ts.node_end_byte(_node); + public TsPoint StartPoint => Ts.node_start_point(_node); + public TsPoint EndPoint => Ts.node_end_point(_node); + public uint ChildCount => Ts.node_child_count(_node); + public uint NamedChildCount => Ts.node_named_child_count(_node); + public TsNode? PreviousSibling + { + get + { + var node = Ts.node_prev_sibling(_node); + return Ts.node_is_null(node) ? null : new(node); + } + } + + public TsNode? NextSibling + { + get + { + var node = Ts.node_next_sibling(_node); + return Ts.node_is_null(node) ? null : new(node); + } + } + + public TsNode? PreviousNamedSibling + { + get + { + var node = Ts.node_prev_named_sibling(_node); + return Ts.node_is_null(node) ? null : new(node); + } + } + + public TsNode? NextNamedSibling + { + get + { + var node = Ts.node_next_named_sibling(_node); + return Ts.node_is_null(node) ? null : new(node); + } + } + + public TsNode? Parent + { + get + { + var node = Ts.node_parent(_node); + return Ts.node_is_null(node) ? null : new(node); + } + } + + public bool IsNamed => Ts.node_is_named(_node); + public bool IsMissing => Ts.node_is_missing(_node); + public bool IsExtra => Ts.node_is_extra(_node); + public bool IsNull => Ts.node_is_null(_node); + + public TsNode GetChildByFieldName(string fieldName) + { + return new TsNode(Ts.node_child_by_field_name(_node, fieldName, (uint)fieldName.Length)); + } + + public TsNode GetChildByFieldId(ushort fieldId) => new(Ts.node_child_by_field_id(_node, fieldId)); + + public string GetFieldNameForChild(uint childIndex) => Ts.node_field_name_for_child(_node, childIndex); + + public TsNode GetNamedChild(uint index) + { + return new TsNode(Ts.node_named_child(_node, index)); + } + + public IEnumerable GetNamedChildren() + { + for (uint i = 0; i < NamedChildCount; i++) + { + yield return GetNamedChild(i); + } + } + + public IEnumerable GetChildren() + { + for (uint i = 0; i < ChildCount; i++) + { + yield return GetChild(i); + } + } + + public TsNode GetChild(uint index) + { + return new TsNode(Ts.node_child(_node, index)); + } + + public Native.TsNode ToUnmanaged() + { + return _node; + } + + public string GetSExpression() + { + return Ts.node_string(_node); + } + + protected bool Equals(TsNode other) => Ts.node_eq(_node, other._node); + + public override bool Equals(object? obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != this.GetType()) + { + return false; + } + + return Equals((TsNode)obj); + } + + public override int GetHashCode() => _node.GetHashCode(); +} diff --git a/src/TreeSitterSharp/Parser.cs b/src/TreeSitterSharp/TsParser.cs similarity index 72% rename from src/TreeSitterSharp/Parser.cs rename to src/TreeSitterSharp/TsParser.cs index cba205a..04f7e7b 100644 --- a/src/TreeSitterSharp/Parser.cs +++ b/src/TreeSitterSharp/TsParser.cs @@ -9,14 +9,14 @@ using TreeSitterSharp.Native; namespace TreeSitterSharp; -public unsafe class Parser +public unsafe class TsParser { - private TsParser* _parser; - private Language? _language; + private Native.TsParser* _parser; + private TsLanguage? _language; - public Parser(Language language) + public TsParser(TsLanguage language) { static void* NewMalloc(nuint byteCount) => NativeMemory.Alloc(byteCount); static void* NewCalloc(nuint count, nuint size) => NativeMemory.AllocZeroed(count * size); @@ -26,12 +26,12 @@ public Parser(Language language) _parser = Ts.parser_new(); Language = language; } - ~Parser() + ~TsParser() { Ts.parser_delete(_parser); } - public Language? Language + public TsLanguage? Language { get => _language; set @@ -44,23 +44,23 @@ public Language? Language } } - public Tree Parse(string code) + public TsTree Parse(string code) { if (_language is null) { throw new Exception("Language can't be null"); } - return new Tree(Ts.parser_parse_string(_parser, null, code, (uint)code.Length)); + return new TsTree(Ts.parser_parse_string(_parser, null, code, (uint)code.Length)); } - public Tree Parse(Span code, Encoding encoding) + public TsTree Parse(Span code, Encoding encoding) { if (_language is null) { throw new Exception("Language can't be null"); } byte[] bytes = Encoding.UTF8.GetBytes(encoding.GetString(code)); - return new Tree(Ts.parser_parse_string_encoding(_parser, null, bytes, (uint)bytes.Length, TsInputEncoding.TSInputEncodingUTF8)); + return new TsTree(Ts.parser_parse_string_encoding(_parser, null, bytes, (uint)bytes.Length, TsInputEncoding.TSInputEncodingUTF8)); } diff --git a/src/TreeSitterSharp/TsTree.cs b/src/TreeSitterSharp/TsTree.cs new file mode 100644 index 0000000..ffac68b --- /dev/null +++ b/src/TreeSitterSharp/TsTree.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TreeSitterSharp.Native; + +namespace TreeSitterSharp; +public unsafe class TsTree +{ + private readonly Native.TsTree* _tree; + + public TsTree(Native.TsTree* tree) + { + _tree = tree; + } + + ~TsTree() + { + Ts.tree_delete(_tree); + } + + public TsTree Copy() => new(Ts.tree_copy(_tree)); + + public TsLanguage Language => new(Ts.tree_language(_tree)); + + public TsNode Root => new(Ts.tree_root_node(_tree)); +} diff --git a/src/TreeSitterSharp/TreeCursor.cs b/src/TreeSitterSharp/TsTreeCursor.cs similarity index 75% rename from src/TreeSitterSharp/TreeCursor.cs rename to src/TreeSitterSharp/TsTreeCursor.cs index 59cd84a..254e5aa 100644 --- a/src/TreeSitterSharp/TreeCursor.cs +++ b/src/TreeSitterSharp/TsTreeCursor.cs @@ -1,26 +1,26 @@ using TreeSitterSharp.Native; namespace TreeSitterSharp; -public class TreeCursor +public class TsTreeCursor { - private readonly TsTreeCursor _treeCursor; - private readonly TsNode _node; + private readonly Native.TsTreeCursor _treeCursor; + private readonly Native.TsNode _node; - public TreeCursor(Node node) + public TsTreeCursor(TsNode node) { _node = node.ToUnmanaged(); _treeCursor = Ts.tree_cursor_new(_node); } - private TreeCursor(TsTreeCursor treeCursor) => _treeCursor = treeCursor; + private TsTreeCursor(Native.TsTreeCursor treeCursor) => _treeCursor = treeCursor; - ~TreeCursor() + ~TsTreeCursor() { Ts.tree_cursor_delete(_treeCursor); } public uint CurrentDepth => Ts.tree_cursor_current_depth(in _treeCursor); - public Node CurrentNode => new(Ts.tree_cursor_current_node(in _treeCursor)); + public TsNode CurrentNode => new(Ts.tree_cursor_current_node(in _treeCursor)); public string CurrentFieldName => Ts.tree_cursor_current_field_name(in _treeCursor); public ushort CurrentFieldId => Ts.tree_cursor_current_field_id(in _treeCursor); public uint CurrentDescendantIndex => Ts.tree_cursor_current_descendant_index(in _treeCursor); @@ -39,13 +39,13 @@ public void Reset() Ts.tree_cursor_reset(_treeCursor, _node); } - public void ResetTo(TreeCursor dst) + public void ResetTo(TsTreeCursor dst) { Ts.tree_cursor_reset_to(dst._treeCursor, _treeCursor); } - public TreeCursor Copy() + public TsTreeCursor Copy() { - return new TreeCursor(Ts.tree_cursor_copy(_treeCursor)); + return new TsTreeCursor(Ts.tree_cursor_copy(_treeCursor)); } } diff --git a/tests/TreeSitterSharp.C.Tests/CParserTests.cs b/tests/TreeSitterSharp.C.Tests/CParserTests.cs index 7cf3c43..766437c 100644 --- a/tests/TreeSitterSharp.C.Tests/CParserTests.cs +++ b/tests/TreeSitterSharp.C.Tests/CParserTests.cs @@ -30,9 +30,8 @@ int fibonacci(int n) { var tree = parser.Parse(code); - var treeCursor = new TreeCursor(tree.Root); + var treeCursor = new TsTreeCursor(tree.Root); var a = treeCursor.GotoFirstChild(); - //var b = treeCursor.GotoFirstChild(); Assert.Equal(expected, tree.Root.GetSExpression()); } } diff --git a/tests/TreeSitterSharp.Json.Tests/JsonParserTests.cs b/tests/TreeSitterSharp.Json.Tests/JsonParserTests.cs index e86746c..02aff38 100644 --- a/tests/TreeSitterSharp.Json.Tests/JsonParserTests.cs +++ b/tests/TreeSitterSharp.Json.Tests/JsonParserTests.cs @@ -11,9 +11,9 @@ public void BasicParsing() var parser = new JsonParser(); string code = "[1, null]"; var tree = parser.Parse(code); - Node rootNode = tree.Root; - Node arrayNode = rootNode.GetNamedChild(0); - Node numberNode = arrayNode.GetNamedChild(0); + TsNode rootNode = tree.Root; + TsNode arrayNode = rootNode.GetNamedChild(0); + TsNode numberNode = arrayNode.GetNamedChild(0); Assert.Equal("document", rootNode.Type); Assert.Equal("array", arrayNode.Type); @@ -31,7 +31,7 @@ public void PrintTree() var parser = new JsonParser(); string code = "[1, null]"; var tree = parser.Parse(code); - Node rootNode = tree.Root; + TsNode rootNode = tree.Root; string expected = """ (document (array (number) (null)))