-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchildren.cpp
More file actions
57 lines (42 loc) · 1.44 KB
/
children.cpp
File metadata and controls
57 lines (42 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "ts/children.hpp"
#include "ts/tree.hpp"
#include "ts/node.hpp"
namespace ts {
Children::Children(TSNode parent, std::shared_ptr<Tree> tree)
: parent(parent), tree(tree) {}
Node Children::operator[](uint32_t index) const {
return Node(ts_node_child(parent, index), tree);
}
uint32_t Children::size() const {
return ts_node_child_count(parent);
}
Children::iterator::iterator(TSNode parent, std::shared_ptr<Tree> tree, uint32_t index)
: parent(parent), tree(tree), index(index) {}
Children::iterator& Children::iterator::findSymbol(TSSymbol symbol) {
for (; index != ts_node_child_count(parent) && ts_node_symbol(ts_node_child(parent, index)) != symbol; ++index)
;
return *this;
}
Node Children::iterator::operator*() const {
return Node(ts_node_child(parent, index), tree);
}
std::unique_ptr<Node> Children::iterator::operator->() const {
return std::make_unique<Node>(ts_node_child(parent, index), tree);
}
Children::iterator& Children::iterator::operator++() {
index++;
return *this;
}
bool Children::iterator::operator==(const iterator& other) const {
return (this->parent.id == other.parent.id) && (index == other.index);
}
bool Children::iterator::operator!=(const iterator& other) const {
return (this->parent.id != other.parent.id) || (index != other.index);
}
Children::iterator Children::begin() const {
return iterator(parent, tree, 0);
}
Children::iterator Children::end() const {
return iterator(parent, tree, size());
}
}