Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Summpot committed Oct 28, 2023
1 parent 65c2c5a commit 9432d31
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
11 changes: 11 additions & 0 deletions publish.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Param(
[switch]$Push
)
$tag = git describe --tags --abbrev=0
$major, $minor, $patch = $tag -split '\.'
$patch = [int]$patch + 1
$newTag = "$major.$minor.$patch"
git tag $newTag
if ($Push) {
git push --tags
}
57 changes: 31 additions & 26 deletions src/TreeSitterSharp/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,66 @@
namespace TreeSitterSharp;
public unsafe struct Node
{
private TsNode _internalNode;
private readonly TsNode _node;

internal Node(TsNode internalNode) => _internalNode = internalNode;
internal Node(TsNode node)
{
_node = node;
Tree = new Tree(_node.tree);
}

public readonly string Type => Ts.node_type(_internalNode);
public readonly uint ChildCount => Ts.node_child_count(_internalNode);
public readonly uint NamedChildCount => Ts.node_named_child_count(_internalNode);
public readonly Node PreviousSibling => new(Ts.node_prev_sibling(_internalNode));
public readonly Node NextSibling => new(Ts.node_next_sibling(_internalNode));
public readonly Node PreviousNamedSibling => new(Ts.node_prev_named_sibling(_internalNode));
public readonly Node NextNamedSibling => new(Ts.node_next_named_sibling(_internalNode));
public readonly Node Parent => new(Ts.node_parent(_internalNode));
public readonly bool IsNull => Ts.node_is_null(_internalNode);
public readonly bool IsNamed => Ts.node_is_named(_internalNode);
public readonly bool IsMissing => Ts.node_is_missing(_internalNode);
public readonly bool IsExtra => Ts.node_is_extra(_internalNode);
public Tree Tree { get; }
public string Type => Ts.node_type(_node);
public uint ChildCount => Ts.node_child_count(_node);
public uint NamedChildCount => Ts.node_named_child_count(_node);
public Node PreviousSibling => new(Ts.node_prev_sibling(_node));
public Node NextSibling => new(Ts.node_next_sibling(_node));
public Node PreviousNamedSibling => new(Ts.node_prev_named_sibling(_node));
public Node NextNamedSibling => new(Ts.node_next_named_sibling(_node));
public Node Parent => new(Ts.node_parent(_node));
public bool IsNull => Ts.node_is_null(_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 readonly Node GetNamedChild(uint index)
public Node GetNamedChild(uint index)
{
return new Node(Ts.node_named_child(_internalNode, index));
return new Node(Ts.node_named_child(_node, index));
}

public readonly IEnumerable<Node> GetNamedChildren()
public IEnumerable<Node> GetNamedChildren()
{
for (uint i = 0; i < NamedChildCount; i++)
{
yield return GetNamedChild(i);
}
}

public readonly IEnumerable<Node> GetChildren()
public IEnumerable<Node> GetChildren()
{
for (uint i = 0; i < ChildCount; i++)
{
yield return GetChild(i);
}
}

public readonly Node GetChildByFieldName(string fieldName)
public Node GetChildByFieldName(string fieldName)
{
return new Node(Ts.node_child_by_field_name(_internalNode, fieldName, (uint)fieldName.Length));
return new Node(Ts.node_child_by_field_name(_node, fieldName, (uint)fieldName.Length));
}

public readonly Node GetChild(uint index)
public Node GetChild(uint index)
{
return new Node(Ts.node_child(_internalNode, index));
return new Node(Ts.node_child(_node, index));
}

public readonly TsNode ToUnmanaged()
public TsNode ToUnmanaged()
{
return _internalNode;
return _node;
}

public readonly string GetSExpression()
public string GetSExpression()
{
return Ts.node_string(_internalNode);
return Ts.node_string(_node);
}
}

0 comments on commit 9432d31

Please sign in to comment.