1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 10:15:55 +03:00

Add a method returning the node’s name as a Swift string.

This commit is contained in:
Rob Rix 2015-10-28 16:55:42 -04:00
parent 3b757bd1e7
commit 56a87154de

View File

@ -3,6 +3,12 @@
typealias TSDocument = COpaquePointer
extension TSNode {
func name(document: TSDocument) throws -> String {
struct E: ErrorType {}
guard let name = String.fromCString(ts_node_name(self, document)) else { throw E() }
return name
}
var children: AnyRandomAccessCollection<TSNode> {
return AnyRandomAccessCollection(ChildrenCollection(node: self, count: ts_node_child_count, child: ts_node_child))
}