-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.cpp
More file actions
54 lines (43 loc) · 1.08 KB
/
Copy pathtree.cpp
File metadata and controls
54 lines (43 loc) · 1.08 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
#include "ts/tree.hpp"
#include "ts/node.hpp"
#include "ts/tree_cursor.hpp"
#include "ts/exceptions.hpp"
namespace ts {
Tree::Tree(TSTree* tree, const string& source, bool keep_text) {
this->source = keep_text ? source : "";
this->tree = tree;
}
Tree::~Tree() {
ts_tree_delete(tree);
}
Node Tree::rootNode() {
return Node(ts_tree_root_node(tree), shared_from_this());
}
const string& Tree::text() const {
if (source.empty()) {
throw NullSourceException();
}
return source;
}
TreeCursor Tree::walk() {
return TreeCursor(Node(ts_tree_root_node(tree), shared_from_this()), shared_from_this());
}
const TreeCursor Tree::walk() const {
return const_cast<Tree*>(this)->walk();
}
void Tree::edit(TSInputEdit edit) {
ts_tree_edit(tree, &edit);
source = nullptr;
}
std::vector<Range> Tree::getChangedRanges(const Tree& newTree) const {
uint32_t length = 0;
TSRange *ranges = ts_tree_get_changed_ranges(tree, newTree.tree, &length);
std::vector<Range> result;
result.resize(length);
for (size_t i = 0; i < length; i++) {
result[i] = ranges[i];
}
free(ranges);
return result;
}
}