smacker / go-tree-sitter

Golang bindings for tree-sitter https://github.com/tree-sitter/tree-sitter
MIT License
444 stars 123 forks source link

Type of idx parameter in Child() and NamedChild() methods. #50

Open m-kru opened 3 years ago

m-kru commented 3 years ago

Child() and NamedChiled() parameters are currently int. Shouldn't they be of type uint32?

// Child returns the node's child at the given index, where zero represents the first child.
func (n Node) Child(idx int) *Node {
    nn := C.ts_node_child(n.c, C.uint32_t(idx))
    return n.t.cachedNode(nn)
}

// NamedChild returns the node's *named* child at the given index.
func (n Node) NamedChild(idx int) *Node {
    nn := C.ts_node_named_child(n.c, C.uint32_t(idx))
    return n.t.cachedNode(nn)
}
m-kru commented 2 years ago

@smacker ping

smacker commented 2 years ago

hi @m-kru ! Is there any particular reason you need it to be unit32?

Int type is at least 32 bytes.

I chose to use int instead of unit32 here because it is the most common integer type in Go according to my experience and is normally used for indexing. Build-in functions such as len or copy also operate with int type which allows to avoid type conversion.

m-kru commented 2 years ago

Well, the only reason is that they are never negative. However, I also understand your point on len and copy.