Remove the TS prefix from some internal type/function names
This commit is contained in:
parent
255bc2427c
commit
c9dcb29c6f
21 changed files with 313 additions and 313 deletions
|
|
@ -14,8 +14,8 @@ bool operator==(const TSRange &left, const TSRange &right) {
|
|||
return left.start == right.start && left.end == right.end;
|
||||
}
|
||||
|
||||
bool operator==(const TSLength &left, const TSLength &right) {
|
||||
return ts_length_eq(left, right);
|
||||
bool operator==(const Length &left, const Length &right) {
|
||||
return length_eq(left, right);
|
||||
}
|
||||
|
||||
bool operator<(const TSPoint &left, const TSPoint &right) {
|
||||
|
|
@ -37,7 +37,7 @@ std::ostream &operator<<(std::ostream &stream, const TSRange &range) {
|
|||
return stream << "{" << range.start << ", " << range.end << "}";
|
||||
}
|
||||
|
||||
ostream &operator<<(ostream &stream, const TSLength &length) {
|
||||
ostream &operator<<(ostream &stream, const Length &length) {
|
||||
return stream << "{chars:" << length.chars << ", bytes:" <<
|
||||
length.bytes << ", extent:" << length.extent << "}";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ bool operator>(const TSPoint &left, const TSPoint &right);
|
|||
|
||||
bool operator==(const TSRange &left, const TSRange &right);
|
||||
|
||||
bool operator==(const TSLength &left, const TSLength &right);
|
||||
bool operator==(const Length &left, const Length &right);
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const TSPoint &point);
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const TSRange &range);
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const TSLength &length);
|
||||
std::ostream &operator<<(std::ostream &stream, const Length &length);
|
||||
|
||||
#endif // HELPERS_POINT_HELPERS_H_
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@ const char *symbol_names[24] = {
|
|||
"twenty-two", "twenty-three"
|
||||
};
|
||||
|
||||
TSTree ** tree_array(std::vector<TSTree *> trees) {
|
||||
TSTree ** result = (TSTree **)calloc(trees.size(), sizeof(TSTree *));
|
||||
Tree ** tree_array(std::vector<Tree *> trees) {
|
||||
Tree ** result = (Tree **)calloc(trees.size(), sizeof(Tree *));
|
||||
for (size_t i = 0; i < trees.size(); i++)
|
||||
result[i] = trees[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
ostream &operator<<(std::ostream &stream, const TSTree *tree) {
|
||||
ostream &operator<<(std::ostream &stream, const Tree *tree) {
|
||||
static TSLanguage DUMMY_LANGUAGE = {};
|
||||
static TSDocument DUMMY_DOCUMENT = {};
|
||||
DUMMY_DOCUMENT.parser.language = &DUMMY_LANGUAGE;
|
||||
|
|
@ -32,7 +32,7 @@ ostream &operator<<(std::ostream &stream, const TSTree *tree) {
|
|||
}
|
||||
|
||||
ostream &operator<<(ostream &stream, const TSNode &node) {
|
||||
return stream << string("{") << (const TSTree *)node.data <<
|
||||
return stream << string("{") << (const Tree *)node.data <<
|
||||
string(", ") << to_string(ts_node_start_char(node)) << string("}");
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ bool operator==(const TSNode &left, const TSNode &right) {
|
|||
return ts_node_eq(left, right);
|
||||
}
|
||||
|
||||
bool operator==(const std::vector<TSTree *> &vec, const TreeArray &array) {
|
||||
bool operator==(const std::vector<Tree *> &vec, const TreeArray &array) {
|
||||
if (vec.size() != array.size)
|
||||
return false;
|
||||
for (size_t i = 0; i < array.size; i++)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
#include <string>
|
||||
|
||||
extern const char *symbol_names[24];
|
||||
TSTree ** tree_array(std::vector<TSTree *> trees);
|
||||
Tree ** tree_array(std::vector<Tree *> trees);
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const TSTree *tree);
|
||||
std::ostream &operator<<(std::ostream &stream, const Tree *tree);
|
||||
std::ostream &operator<<(std::ostream &stream, const TSNode &node);
|
||||
bool operator==(const TSNode &left, const TSNode &right);
|
||||
bool operator==(const std::vector<TSTree *> &right, const TreeArray &array);
|
||||
bool operator==(const std::vector<Tree *> &right, const TreeArray &array);
|
||||
|
||||
#endif // HELPERS_TREE_HELPERS_H_
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ enum {
|
|||
symbol9, symbol10
|
||||
};
|
||||
|
||||
TSLength operator*(const TSLength &length, size_t factor) {
|
||||
Length operator*(const Length &length, size_t factor) {
|
||||
return {length.bytes * factor, length.chars * factor, {0, length.extent.column * factor}};
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +69,8 @@ START_TEST
|
|||
describe("Stack", [&]() {
|
||||
Stack *stack;
|
||||
const size_t tree_count = 11;
|
||||
TSTree *trees[tree_count];
|
||||
TSLength tree_len = {2, 3, {0, 3}};
|
||||
Tree *trees[tree_count];
|
||||
Length tree_len = {2, 3, {0, 3}};
|
||||
|
||||
before_each([&]() {
|
||||
record_alloc::start();
|
||||
|
|
@ -78,7 +78,7 @@ describe("Stack", [&]() {
|
|||
stack = ts_stack_new();
|
||||
|
||||
for (size_t i = 0; i < tree_count; i++)
|
||||
trees[i] = ts_tree_make_leaf(i, ts_length_zero(), tree_len, {
|
||||
trees[i] = ts_tree_make_leaf(i, length_zero(), tree_len, {
|
||||
true, true, false, true,
|
||||
});
|
||||
});
|
||||
|
|
@ -96,7 +96,7 @@ describe("Stack", [&]() {
|
|||
it("adds entries to the given version of the stack", [&]() {
|
||||
AssertThat(ts_stack_version_count(stack), Equals<size_t>(1));
|
||||
AssertThat(ts_stack_top_state(stack, 0), Equals(1));
|
||||
AssertThat(ts_stack_top_position(stack, 0), Equals(ts_length_zero()));
|
||||
AssertThat(ts_stack_top_position(stack, 0), Equals(length_zero()));
|
||||
|
||||
// . <──0── A*
|
||||
ts_stack_push(stack, 0, trees[0], false, stateA);
|
||||
|
|
@ -223,7 +223,7 @@ describe("Stack", [&]() {
|
|||
|
||||
StackSlice slice = pop.slices.contents[0];
|
||||
AssertThat(slice.version, Equals<StackVersion>(1));
|
||||
AssertThat(slice.trees, Equals(vector<TSTree *>({ trees[1], trees[2] })));
|
||||
AssertThat(slice.trees, Equals(vector<Tree *>({ trees[1], trees[2] })));
|
||||
AssertThat(ts_stack_top_state(stack, 1), Equals(stateA));
|
||||
|
||||
free_slice_array(&pop.slices);
|
||||
|
|
@ -240,7 +240,7 @@ describe("Stack", [&]() {
|
|||
AssertThat(pop.slices.size, Equals<size_t>(1));
|
||||
|
||||
StackSlice slice = pop.slices.contents[0];
|
||||
AssertThat(slice.trees, Equals(vector<TSTree *>({ trees[0], trees[1], trees[2] })));
|
||||
AssertThat(slice.trees, Equals(vector<Tree *>({ trees[0], trees[1], trees[2] })));
|
||||
AssertThat(ts_stack_top_state(stack, 1), Equals(1));
|
||||
|
||||
free_slice_array(&pop.slices);
|
||||
|
|
@ -263,7 +263,7 @@ describe("Stack", [&]() {
|
|||
AssertThat(pop.slices.size, Equals<size_t>(1));
|
||||
StackSlice slice = pop.slices.contents[0];
|
||||
AssertThat(slice.version, Equals<StackVersion>(1));
|
||||
AssertThat(slice.trees, Equals(vector<TSTree *>({ trees[4] })));
|
||||
AssertThat(slice.trees, Equals(vector<Tree *>({ trees[4] })));
|
||||
|
||||
free_slice_array(&pop.slices);
|
||||
});
|
||||
|
|
@ -319,11 +319,11 @@ describe("Stack", [&]() {
|
|||
|
||||
StackSlice slice1 = pop.slices.contents[0];
|
||||
AssertThat(slice1.version, Equals<StackVersion>(1));
|
||||
AssertThat(slice1.trees, Equals(vector<TSTree *>({ trees[2], trees[3], trees[10] })));
|
||||
AssertThat(slice1.trees, Equals(vector<Tree *>({ trees[2], trees[3], trees[10] })));
|
||||
|
||||
StackSlice slice2 = pop.slices.contents[1];
|
||||
AssertThat(slice2.version, Equals<StackVersion>(2));
|
||||
AssertThat(slice2.trees, Equals(vector<TSTree *>({ trees[5], trees[6], trees[10] })));
|
||||
AssertThat(slice2.trees, Equals(vector<Tree *>({ trees[5], trees[6], trees[10] })));
|
||||
|
||||
AssertThat(ts_stack_version_count(stack), Equals<size_t>(3));
|
||||
AssertThat(get_stack_entries(stack, 0), Equals(vector<StackEntry>({
|
||||
|
|
@ -363,7 +363,7 @@ describe("Stack", [&]() {
|
|||
|
||||
StackSlice slice1 = pop.slices.contents[0];
|
||||
AssertThat(slice1.version, Equals<StackVersion>(1));
|
||||
AssertThat(slice1.trees, Equals(vector<TSTree *>({ trees[10] })));
|
||||
AssertThat(slice1.trees, Equals(vector<Tree *>({ trees[10] })));
|
||||
|
||||
AssertThat(ts_stack_version_count(stack), Equals<size_t>(2));
|
||||
AssertThat(ts_stack_top_state(stack, 0), Equals(stateI));
|
||||
|
|
@ -385,11 +385,11 @@ describe("Stack", [&]() {
|
|||
|
||||
StackSlice slice1 = pop.slices.contents[0];
|
||||
AssertThat(slice1.version, Equals<StackVersion>(1));
|
||||
AssertThat(slice1.trees, Equals(vector<TSTree *>({ trees[1], trees[2], trees[3], trees[10] })));
|
||||
AssertThat(slice1.trees, Equals(vector<Tree *>({ trees[1], trees[2], trees[3], trees[10] })));
|
||||
|
||||
StackSlice slice2 = pop.slices.contents[1];
|
||||
AssertThat(slice2.version, Equals<StackVersion>(1));
|
||||
AssertThat(slice2.trees, Equals(vector<TSTree *>({ trees[4], trees[5], trees[6], trees[10] })))
|
||||
AssertThat(slice2.trees, Equals(vector<Tree *>({ trees[4], trees[5], trees[6], trees[10] })))
|
||||
|
||||
AssertThat(ts_stack_version_count(stack), Equals<size_t>(2));
|
||||
AssertThat(ts_stack_top_state(stack, 0), Equals(stateI));
|
||||
|
|
@ -440,15 +440,15 @@ describe("Stack", [&]() {
|
|||
|
||||
StackSlice slice1 = pop.slices.contents[0];
|
||||
AssertThat(slice1.version, Equals<StackVersion>(1));
|
||||
AssertThat(slice1.trees, Equals(vector<TSTree *>({ trees[3], trees[10] })))
|
||||
AssertThat(slice1.trees, Equals(vector<Tree *>({ trees[3], trees[10] })))
|
||||
|
||||
StackSlice slice2 = pop.slices.contents[1];
|
||||
AssertThat(slice2.version, Equals<StackVersion>(2));
|
||||
AssertThat(slice2.trees, Equals(vector<TSTree *>({ trees[6], trees[10] })))
|
||||
AssertThat(slice2.trees, Equals(vector<Tree *>({ trees[6], trees[10] })))
|
||||
|
||||
StackSlice slice3 = pop.slices.contents[2];
|
||||
AssertThat(slice3.version, Equals<StackVersion>(3));
|
||||
AssertThat(slice3.trees, Equals(vector<TSTree *>({ trees[9], trees[10] })))
|
||||
AssertThat(slice3.trees, Equals(vector<Tree *>({ trees[9], trees[10] })))
|
||||
|
||||
AssertThat(ts_stack_version_count(stack), Equals<size_t>(4));
|
||||
AssertThat(ts_stack_top_state(stack, 0), Equals(stateI));
|
||||
|
|
@ -495,7 +495,7 @@ describe("Stack", [&]() {
|
|||
AssertThat(pop.stopped_at_error, Equals(false));
|
||||
AssertThat(pop.slices.size, Equals<size_t>(1));
|
||||
|
||||
AssertThat(pop.slices.contents[0].trees, Equals(vector<TSTree *>({ trees[1], trees[2], trees[3] })));
|
||||
AssertThat(pop.slices.contents[0].trees, Equals(vector<Tree *>({ trees[1], trees[2], trees[3] })));
|
||||
|
||||
AssertThat(get_stack_entries(stack, 0), Equals(vector<StackEntry>({
|
||||
{stateA, 0},
|
||||
|
|
|
|||
|
|
@ -4,20 +4,20 @@
|
|||
#include "runtime/tree.h"
|
||||
#include "runtime/length.h"
|
||||
|
||||
void assert_consistent(const TSTree *tree) {
|
||||
void assert_consistent(const Tree *tree) {
|
||||
if (tree->child_count == 0)
|
||||
return;
|
||||
AssertThat(tree->children[0]->padding, Equals<TSLength>(tree->padding));
|
||||
AssertThat(tree->children[0]->padding, Equals<Length>(tree->padding));
|
||||
|
||||
TSLength total_children_size = ts_length_zero();
|
||||
Length total_children_size = length_zero();
|
||||
for (size_t i = 0; i < tree->child_count; i++) {
|
||||
TSTree *child = tree->children[i];
|
||||
Tree *child = tree->children[i];
|
||||
AssertThat(child->context.offset, Equals(total_children_size));
|
||||
assert_consistent(child);
|
||||
total_children_size = ts_length_add(total_children_size, ts_tree_total_size(child));
|
||||
total_children_size = length_add(total_children_size, ts_tree_total_size(child));
|
||||
}
|
||||
|
||||
AssertThat(total_children_size, Equals<TSLength>(ts_tree_total_size(tree)));
|
||||
AssertThat(total_children_size, Equals<Length>(ts_tree_total_size(tree)));
|
||||
};
|
||||
|
||||
START_TEST
|
||||
|
|
@ -32,7 +32,7 @@ enum {
|
|||
};
|
||||
|
||||
describe("Tree", []() {
|
||||
TSTree *tree1, *tree2, *parent1;
|
||||
Tree *tree1, *tree2, *parent1;
|
||||
TSSymbolMetadata visible = {true, true, false, true};
|
||||
TSSymbolMetadata invisible = {false, false, false, true};
|
||||
|
||||
|
|
@ -63,9 +63,9 @@ describe("Tree", []() {
|
|||
|
||||
describe("make_error(size, padding, lookahead_char)", [&]() {
|
||||
it("records that it is fragile", [&]() {
|
||||
TSTree *error_tree = ts_tree_make_error(
|
||||
ts_length_zero(),
|
||||
ts_length_zero(),
|
||||
Tree *error_tree = ts_tree_make_error(
|
||||
length_zero(),
|
||||
length_zero(),
|
||||
'z');
|
||||
|
||||
AssertThat(error_tree->fragile_left, IsTrue());
|
||||
|
|
@ -89,7 +89,7 @@ describe("Tree", []() {
|
|||
});
|
||||
|
||||
describe("when the first node is fragile on the left side", [&]() {
|
||||
TSTree *parent;
|
||||
Tree *parent;
|
||||
|
||||
before_each([&]() {
|
||||
tree1->fragile_left = true;
|
||||
|
|
@ -113,7 +113,7 @@ describe("Tree", []() {
|
|||
});
|
||||
|
||||
describe("when the last node is fragile on the right side", [&]() {
|
||||
TSTree *parent;
|
||||
Tree *parent;
|
||||
|
||||
before_each([&]() {
|
||||
tree2->fragile_right = true;
|
||||
|
|
@ -137,7 +137,7 @@ describe("Tree", []() {
|
|||
});
|
||||
|
||||
describe("when the outer nodes aren't fragile on their outer side", [&]() {
|
||||
TSTree *parent;
|
||||
Tree *parent;
|
||||
|
||||
before_each([&]() {
|
||||
tree1->fragile_right = true;
|
||||
|
|
@ -163,7 +163,7 @@ describe("Tree", []() {
|
|||
});
|
||||
|
||||
describe("edit(InputEdit)", [&]() {
|
||||
TSTree *tree = nullptr;
|
||||
Tree *tree = nullptr;
|
||||
|
||||
before_each([&]() {
|
||||
tree = ts_tree_make_node(cat, 3, tree_array({
|
||||
|
|
@ -172,8 +172,8 @@ describe("Tree", []() {
|
|||
ts_tree_make_leaf(fox, {2, 2, {0, 2}}, {3, 3, {0, 3}}, visible),
|
||||
}), visible);
|
||||
|
||||
AssertThat(tree->padding, Equals<TSLength>({2, 2, {0, 2}}));
|
||||
AssertThat(tree->size, Equals<TSLength>({13, 13, {0, 13}}));
|
||||
AssertThat(tree->padding, Equals<Length>({2, 2, {0, 2}}));
|
||||
AssertThat(tree->size, Equals<Length>({13, 13, {0, 13}}));
|
||||
});
|
||||
|
||||
after_each([&]() {
|
||||
|
|
@ -194,16 +194,16 @@ describe("Tree", []() {
|
|||
assert_consistent(tree);
|
||||
|
||||
AssertThat(tree->has_changes, IsTrue());
|
||||
AssertThat(tree->padding, Equals<TSLength>({3, 0, {0, 3}}));
|
||||
AssertThat(tree->size, Equals<TSLength>({13, 13, {0, 13}}));
|
||||
AssertThat(tree->padding, Equals<Length>({3, 0, {0, 3}}));
|
||||
AssertThat(tree->size, Equals<Length>({13, 13, {0, 13}}));
|
||||
|
||||
AssertThat(tree->children[0]->has_changes, IsTrue());
|
||||
AssertThat(tree->children[0]->padding, Equals<TSLength>({3, 0, {0, 3}}));
|
||||
AssertThat(tree->children[0]->size, Equals<TSLength>({3, 3, {0, 3}}));
|
||||
AssertThat(tree->children[0]->padding, Equals<Length>({3, 0, {0, 3}}));
|
||||
AssertThat(tree->children[0]->size, Equals<Length>({3, 3, {0, 3}}));
|
||||
|
||||
AssertThat(tree->children[1]->has_changes, IsFalse());
|
||||
AssertThat(tree->children[1]->padding, Equals<TSLength>({2, 2, {0, 2}}));
|
||||
AssertThat(tree->children[1]->size, Equals<TSLength>({3, 3, {0, 3}}));
|
||||
AssertThat(tree->children[1]->padding, Equals<Length>({2, 2, {0, 2}}));
|
||||
AssertThat(tree->children[1]->size, Equals<Length>({3, 3, {0, 3}}));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -220,12 +220,12 @@ describe("Tree", []() {
|
|||
assert_consistent(tree);
|
||||
|
||||
AssertThat(tree->has_changes, IsTrue());
|
||||
AssertThat(tree->padding, Equals<TSLength>({5, 0, {0, 5}}));
|
||||
AssertThat(tree->size, Equals<TSLength>({11, 0, {0, 11}}));
|
||||
AssertThat(tree->padding, Equals<Length>({5, 0, {0, 5}}));
|
||||
AssertThat(tree->size, Equals<Length>({11, 0, {0, 11}}));
|
||||
|
||||
AssertThat(tree->children[0]->has_changes, IsTrue());
|
||||
AssertThat(tree->children[0]->padding, Equals<TSLength>({5, 0, {0, 5}}));
|
||||
AssertThat(tree->children[0]->size, Equals<TSLength>({1, 0, {0, 1}}));
|
||||
AssertThat(tree->children[0]->padding, Equals<Length>({5, 0, {0, 5}}));
|
||||
AssertThat(tree->children[0]->size, Equals<Length>({1, 0, {0, 1}}));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -244,12 +244,12 @@ describe("Tree", []() {
|
|||
assert_consistent(tree);
|
||||
|
||||
AssertThat(tree->has_changes, IsTrue());
|
||||
AssertThat(tree->padding, Equals<TSLength>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->size, Equals<TSLength>({13, 13, {0, 13}}));
|
||||
AssertThat(tree->padding, Equals<Length>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->size, Equals<Length>({13, 13, {0, 13}}));
|
||||
|
||||
AssertThat(tree->children[0]->has_changes, IsTrue());
|
||||
AssertThat(tree->children[0]->padding, Equals<TSLength>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->children[0]->size, Equals<TSLength>({3, 3, {0, 3}}));
|
||||
AssertThat(tree->children[0]->padding, Equals<Length>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->children[0]->size, Equals<Length>({3, 3, {0, 3}}));
|
||||
|
||||
AssertThat(tree->children[1]->has_changes, IsFalse());
|
||||
});
|
||||
|
|
@ -268,12 +268,12 @@ describe("Tree", []() {
|
|||
assert_consistent(tree);
|
||||
|
||||
AssertThat(tree->has_changes, IsTrue());
|
||||
AssertThat(tree->padding, Equals<TSLength>({2, 2, {0, 2}}));
|
||||
AssertThat(tree->size, Equals<TSLength>({16, 0, {0, 16}}));
|
||||
AssertThat(tree->padding, Equals<Length>({2, 2, {0, 2}}));
|
||||
AssertThat(tree->size, Equals<Length>({16, 0, {0, 16}}));
|
||||
|
||||
AssertThat(tree->children[0]->has_changes, IsTrue());
|
||||
AssertThat(tree->children[0]->padding, Equals<TSLength>({2, 2, {0, 2}}));
|
||||
AssertThat(tree->children[0]->size, Equals<TSLength>({6, 0, {0, 6}}));
|
||||
AssertThat(tree->children[0]->padding, Equals<Length>({2, 2, {0, 2}}));
|
||||
AssertThat(tree->children[0]->size, Equals<Length>({6, 0, {0, 6}}));
|
||||
|
||||
AssertThat(tree->children[1]->has_changes, IsFalse());
|
||||
});
|
||||
|
|
@ -294,33 +294,33 @@ describe("Tree", []() {
|
|||
assert_consistent(tree);
|
||||
|
||||
AssertThat(tree->has_changes, IsTrue());
|
||||
AssertThat(tree->padding, Equals<TSLength>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->size, Equals<TSLength>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->padding, Equals<Length>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->size, Equals<Length>({4, 0, {0, 4}}));
|
||||
|
||||
AssertThat(tree->children[0]->has_changes, IsTrue());
|
||||
AssertThat(tree->children[0]->padding, Equals<TSLength>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->children[0]->size, Equals<TSLength>({0, 0, {0, 0}}));
|
||||
AssertThat(tree->children[0]->padding, Equals<Length>({4, 0, {0, 4}}));
|
||||
AssertThat(tree->children[0]->size, Equals<Length>({0, 0, {0, 0}}));
|
||||
|
||||
AssertThat(tree->children[1]->has_changes, IsTrue());
|
||||
AssertThat(tree->children[1]->padding, Equals<TSLength>({0, 0, {0, 0}}));
|
||||
AssertThat(tree->children[1]->size, Equals<TSLength>({0, 0, {0, 0}}));
|
||||
AssertThat(tree->children[1]->padding, Equals<Length>({0, 0, {0, 0}}));
|
||||
AssertThat(tree->children[1]->size, Equals<Length>({0, 0, {0, 0}}));
|
||||
|
||||
AssertThat(tree->children[2]->has_changes, IsTrue());
|
||||
AssertThat(tree->children[2]->padding, Equals<TSLength>({1, 0, {0, 1}}));
|
||||
AssertThat(tree->children[2]->size, Equals<TSLength>({3, 3, {0, 3}}));
|
||||
AssertThat(tree->children[2]->padding, Equals<Length>({1, 0, {0, 1}}));
|
||||
AssertThat(tree->children[2]->size, Equals<Length>({3, 3, {0, 3}}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("equality", [&]() {
|
||||
it("returns true for identical trees", [&]() {
|
||||
TSTree *tree1_copy = ts_tree_make_leaf(cat, {2, 1, {1, 1}}, {5, 4, {1, 4}}, visible);
|
||||
Tree *tree1_copy = ts_tree_make_leaf(cat, {2, 1, {1, 1}}, {5, 4, {1, 4}}, visible);
|
||||
AssertThat(ts_tree_eq(tree1, tree1_copy), IsTrue());
|
||||
|
||||
TSTree *tree2_copy = ts_tree_make_leaf(cat, {1, 1, {0, 1}}, {3, 3, {0, 3}}, visible);
|
||||
Tree *tree2_copy = ts_tree_make_leaf(cat, {1, 1, {0, 1}}, {3, 3, {0, 3}}, visible);
|
||||
AssertThat(ts_tree_eq(tree2, tree2_copy), IsTrue());
|
||||
|
||||
TSTree *parent2 = ts_tree_make_node(dog, 2, tree_array({
|
||||
Tree *parent2 = ts_tree_make_node(dog, 2, tree_array({
|
||||
tree1_copy,
|
||||
tree2_copy,
|
||||
}), visible);
|
||||
|
|
@ -331,7 +331,7 @@ describe("Tree", []() {
|
|||
});
|
||||
|
||||
it("returns false for trees with different symbols", [&]() {
|
||||
TSTree *different_tree = ts_tree_make_leaf(
|
||||
Tree *different_tree = ts_tree_make_leaf(
|
||||
tree1->symbol + 1,
|
||||
tree1->padding,
|
||||
tree1->size,
|
||||
|
|
@ -342,13 +342,13 @@ describe("Tree", []() {
|
|||
});
|
||||
|
||||
it("returns false for trees with different options", [&]() {
|
||||
TSTree *tree1_copy = ts_tree_make_leaf(cat, tree1->padding, tree1->size, invisible);
|
||||
Tree *tree1_copy = ts_tree_make_leaf(cat, tree1->padding, tree1->size, invisible);
|
||||
AssertThat(ts_tree_eq(tree1, tree1_copy), IsFalse());
|
||||
ts_tree_release(tree1_copy);
|
||||
});
|
||||
|
||||
it("returns false for trees with different sizes", [&]() {
|
||||
TSTree *tree1_copy = ts_tree_make_leaf(cat, {2, 1, {0, 1}}, tree1->size, invisible);
|
||||
Tree *tree1_copy = ts_tree_make_leaf(cat, {2, 1, {0, 1}}, tree1->size, invisible);
|
||||
AssertThat(ts_tree_eq(tree1, tree1_copy), IsFalse());
|
||||
ts_tree_release(tree1_copy);
|
||||
|
||||
|
|
@ -358,7 +358,7 @@ describe("Tree", []() {
|
|||
});
|
||||
|
||||
it("returns false for trees with different children", [&]() {
|
||||
TSTree *different_tree = ts_tree_make_leaf(
|
||||
Tree *different_tree = ts_tree_make_leaf(
|
||||
tree1->symbol + 1,
|
||||
tree1->padding,
|
||||
tree1->size,
|
||||
|
|
@ -366,7 +366,7 @@ describe("Tree", []() {
|
|||
|
||||
ts_tree_retain(different_tree);
|
||||
ts_tree_retain(tree2);
|
||||
TSTree *different_parent = ts_tree_make_node(dog, 2, tree_array({
|
||||
Tree *different_parent = ts_tree_make_node(dog, 2, tree_array({
|
||||
different_tree, tree2,
|
||||
}), visible);
|
||||
|
||||
|
|
|
|||
|
|
@ -97,14 +97,14 @@ void ts_document_parse_and_get_changed_ranges(TSDocument *self, TSRange **ranges
|
|||
if (!self->input.read || !self->parser.language)
|
||||
return;
|
||||
|
||||
TSTree *reusable_tree = self->valid ? self->tree : NULL;
|
||||
Tree *reusable_tree = self->valid ? self->tree : NULL;
|
||||
if (reusable_tree && !reusable_tree->has_changes)
|
||||
return;
|
||||
|
||||
TSTree *tree = parser_parse(&self->parser, self->input, reusable_tree);
|
||||
Tree *tree = parser_parse(&self->parser, self->input, reusable_tree);
|
||||
|
||||
if (self->tree) {
|
||||
TSTree *old_tree = self->tree;
|
||||
Tree *old_tree = self->tree;
|
||||
self->tree = tree;
|
||||
|
||||
if (ranges && range_count) {
|
||||
|
|
@ -132,7 +132,7 @@ void ts_document_invalidate(TSDocument *self) {
|
|||
|
||||
TSNode ts_document_root_node(const TSDocument *self) {
|
||||
TSNode result = ts_node_make(self->tree, 0, 0, 0);
|
||||
while (result.data && !((TSTree *)result.data)->visible)
|
||||
while (result.data && !((Tree *)result.data)->visible)
|
||||
result = ts_node_named_child(result, 0);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
struct TSDocument {
|
||||
Parser parser;
|
||||
TSInput input;
|
||||
TSTree *tree;
|
||||
Tree *tree;
|
||||
size_t parse_count;
|
||||
bool valid;
|
||||
bool owns_input;
|
||||
|
|
|
|||
|
|
@ -10,27 +10,27 @@ typedef struct {
|
|||
size_t bytes;
|
||||
size_t chars;
|
||||
TSPoint extent;
|
||||
} TSLength;
|
||||
} Length;
|
||||
|
||||
static inline bool ts_length_has_unknown_chars(TSLength self) {
|
||||
static inline bool length_has_unknown_chars(Length self) {
|
||||
return self.bytes > 0 && self.chars == 0;
|
||||
}
|
||||
|
||||
static inline void ts_length_set_unknown_chars(TSLength *self) {
|
||||
static inline void length_set_unknown_chars(Length *self) {
|
||||
self->chars = 0;
|
||||
}
|
||||
|
||||
static inline TSLength ts_length_min(TSLength len1, TSLength len2) {
|
||||
static inline Length length_min(Length len1, Length len2) {
|
||||
return (len1.chars < len2.chars) ? len1 : len2;
|
||||
}
|
||||
|
||||
static inline TSLength ts_length_add(TSLength len1, TSLength len2) {
|
||||
TSLength result;
|
||||
static inline Length length_add(Length len1, Length len2) {
|
||||
Length result;
|
||||
result.chars = len1.chars + len2.chars;
|
||||
result.bytes = len1.bytes + len2.bytes;
|
||||
result.extent = ts_point_add(len1.extent, len2.extent);
|
||||
result.extent = point_add(len1.extent, len2.extent);
|
||||
|
||||
if (ts_length_has_unknown_chars(len1) || ts_length_has_unknown_chars(len2)) {
|
||||
if (length_has_unknown_chars(len1) || length_has_unknown_chars(len2)) {
|
||||
result.chars = 0;
|
||||
} else {
|
||||
result.chars = len1.chars + len2.chars;
|
||||
|
|
@ -39,12 +39,12 @@ static inline TSLength ts_length_add(TSLength len1, TSLength len2) {
|
|||
return result;
|
||||
}
|
||||
|
||||
static inline TSLength ts_length_sub(TSLength len1, TSLength len2) {
|
||||
TSLength result;
|
||||
static inline Length length_sub(Length len1, Length len2) {
|
||||
Length result;
|
||||
result.bytes = len1.bytes - len2.bytes;
|
||||
result.extent = ts_point_sub(len1.extent, len2.extent);
|
||||
result.extent = point_sub(len1.extent, len2.extent);
|
||||
|
||||
if (ts_length_has_unknown_chars(len1) || ts_length_has_unknown_chars(len2)) {
|
||||
if (length_has_unknown_chars(len1) || length_has_unknown_chars(len2)) {
|
||||
result.chars = 0;
|
||||
} else {
|
||||
result.chars = len1.chars - len2.chars;
|
||||
|
|
@ -53,11 +53,11 @@ static inline TSLength ts_length_sub(TSLength len1, TSLength len2) {
|
|||
return result;
|
||||
}
|
||||
|
||||
static inline TSLength ts_length_zero() {
|
||||
return (TSLength){ 0, 0, {0, 0} };
|
||||
static inline Length length_zero() {
|
||||
return (Length){ 0, 0, {0, 0} };
|
||||
}
|
||||
|
||||
static inline bool ts_length_eq(TSLength self, TSLength other) {
|
||||
static inline bool length_eq(Length self, Length other) {
|
||||
return self.bytes == other.bytes && self.chars == other.chars &&
|
||||
self.extent.row == other.extent.row &&
|
||||
self.extent.column == other.extent.column;
|
||||
|
|
|
|||
|
|
@ -90,10 +90,10 @@ void ts_lexer_init(Lexer *self) {
|
|||
.chunk_start = 0,
|
||||
.logger = {},
|
||||
};
|
||||
ts_lexer_reset(self, ts_length_zero());
|
||||
ts_lexer_reset(self, length_zero());
|
||||
}
|
||||
|
||||
static inline void ts_lexer__reset(Lexer *self, TSLength position) {
|
||||
static inline void ts_lexer__reset(Lexer *self, Length position) {
|
||||
self->token_start_position = position;
|
||||
self->current_position = position;
|
||||
|
||||
|
|
@ -110,11 +110,11 @@ static inline void ts_lexer__reset(Lexer *self, TSLength position) {
|
|||
|
||||
void ts_lexer_set_input(Lexer *self, TSInput input) {
|
||||
self->input = input;
|
||||
ts_lexer__reset(self, ts_length_zero());
|
||||
ts_lexer__reset(self, length_zero());
|
||||
}
|
||||
|
||||
void ts_lexer_reset(Lexer *self, TSLength position) {
|
||||
if (!ts_length_eq(position, self->current_position))
|
||||
void ts_lexer_reset(Lexer *self, Length position) {
|
||||
if (!length_eq(position, self->current_position))
|
||||
ts_lexer__reset(self, position);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ extern "C" {
|
|||
|
||||
typedef struct {
|
||||
TSLexer data;
|
||||
TSLength current_position;
|
||||
TSLength token_start_position;
|
||||
Length current_position;
|
||||
Length token_start_position;
|
||||
|
||||
const char *chunk;
|
||||
size_t chunk_start;
|
||||
|
|
@ -29,7 +29,7 @@ typedef struct {
|
|||
|
||||
void ts_lexer_init(Lexer *);
|
||||
void ts_lexer_set_input(Lexer *, TSInput);
|
||||
void ts_lexer_reset(Lexer *, TSLength);
|
||||
void ts_lexer_reset(Lexer *, Length);
|
||||
void ts_lexer_start(Lexer *, TSStateId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "runtime/tree.h"
|
||||
#include "runtime/document.h"
|
||||
|
||||
TSNode ts_node_make(const TSTree *tree, size_t chars, size_t byte, size_t row) {
|
||||
TSNode ts_node_make(const Tree *tree, size_t chars, size_t byte, size_t row) {
|
||||
return (TSNode){.data = tree, .offset = { chars, byte, row } };
|
||||
}
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ static inline TSNode ts_node__null() {
|
|||
return ts_node_make(NULL, 0, 0, 0);
|
||||
}
|
||||
|
||||
static inline const TSTree *ts_node__tree(TSNode self) {
|
||||
static inline const Tree *ts_node__tree(TSNode self) {
|
||||
return self.data;
|
||||
}
|
||||
|
||||
|
|
@ -32,18 +32,18 @@ static inline size_t ts_node__offset_row(TSNode self) {
|
|||
}
|
||||
|
||||
static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) {
|
||||
const TSTree *tree = ts_node__tree(self);
|
||||
const Tree *tree = ts_node__tree(self);
|
||||
return include_anonymous ? tree->visible : tree->visible && tree->named;
|
||||
}
|
||||
|
||||
static inline size_t ts_node__relevant_child_count(TSNode self,
|
||||
bool include_anonymous) {
|
||||
const TSTree *tree = ts_node__tree(self);
|
||||
const Tree *tree = ts_node__tree(self);
|
||||
return include_anonymous ? tree->visible_child_count : tree->named_child_count;
|
||||
}
|
||||
|
||||
static inline TSNode ts_node__direct_parent(TSNode self, size_t *index) {
|
||||
const TSTree *tree = ts_node__tree(self);
|
||||
const Tree *tree = ts_node__tree(self);
|
||||
*index = tree->context.index;
|
||||
return ts_node_make(tree->context.parent,
|
||||
ts_node__offset_char(self) - tree->context.offset.chars,
|
||||
|
|
@ -52,7 +52,7 @@ static inline TSNode ts_node__direct_parent(TSNode self, size_t *index) {
|
|||
}
|
||||
|
||||
static inline TSNode ts_node__direct_child(TSNode self, size_t i) {
|
||||
const TSTree *child_tree = ts_node__tree(self)->children[i];
|
||||
const Tree *child_tree = ts_node__tree(self)->children[i];
|
||||
return ts_node_make(
|
||||
child_tree, ts_node__offset_char(self) + child_tree->context.offset.chars,
|
||||
ts_node__offset_byte(self) + child_tree->context.offset.bytes,
|
||||
|
|
@ -138,7 +138,7 @@ static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous)
|
|||
return ts_node__null();
|
||||
}
|
||||
|
||||
static inline bool ts_point_gt(TSPoint a, TSPoint b) {
|
||||
static inline bool point_gt(TSPoint a, TSPoint b) {
|
||||
return a.row > b.row || (a.row == b.row && a.column > b.column);
|
||||
}
|
||||
|
||||
|
|
@ -207,9 +207,9 @@ static inline TSNode ts_node__descendant_for_point_range(
|
|||
|
||||
for (size_t i = 0; i < ts_node__tree(node)->child_count; i++) {
|
||||
TSNode child = ts_node__direct_child(node, i);
|
||||
if (ts_point_gt(ts_node_start_point(child), min))
|
||||
if (point_gt(ts_node_start_point(child), min))
|
||||
break;
|
||||
if (ts_point_gt(ts_node_end_point(child), max)) {
|
||||
if (point_gt(ts_node_end_point(child), max)) {
|
||||
node = child;
|
||||
if (ts_node__is_relevant(node, include_anonymous))
|
||||
last_visible_node = node;
|
||||
|
|
@ -243,13 +243,13 @@ size_t ts_node_end_byte(TSNode self) {
|
|||
}
|
||||
|
||||
TSPoint ts_node_start_point(TSNode self) {
|
||||
const TSTree *tree = ts_node__tree(self);
|
||||
const Tree *tree = ts_node__tree(self);
|
||||
return (TSPoint){ ts_node__offset_row(self) + tree->padding.extent.row,
|
||||
ts_tree_start_column(tree) };
|
||||
}
|
||||
|
||||
TSPoint ts_node_end_point(TSNode self) {
|
||||
const TSTree *tree = ts_node__tree(self);
|
||||
const Tree *tree = ts_node__tree(self);
|
||||
return (TSPoint){ ts_node__offset_row(self) + tree->padding.extent.row +
|
||||
tree->size.extent.row,
|
||||
ts_tree_end_column(tree) };
|
||||
|
|
@ -260,15 +260,15 @@ TSSymbol ts_node_symbol(TSNode self) {
|
|||
}
|
||||
|
||||
TSSymbolIterator ts_node_symbols(TSNode self) {
|
||||
const TSTree *tree = ts_node__tree(self);
|
||||
const Tree *tree = ts_node__tree(self);
|
||||
return (TSSymbolIterator){
|
||||
.value = tree->symbol, .done = false, .data = (void *)tree,
|
||||
};
|
||||
}
|
||||
|
||||
void ts_symbol_iterator_next(TSSymbolIterator *self) {
|
||||
const TSTree *tree = (const TSTree *)self->data;
|
||||
const TSTree *parent = tree->context.parent;
|
||||
const Tree *tree = (const Tree *)self->data;
|
||||
const Tree *parent = tree->context.parent;
|
||||
if (!self->done && parent) {
|
||||
if (parent->child_count == 1 && !parent->visible) {
|
||||
self->value = parent->symbol;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#include "runtime/tree.h"
|
||||
|
||||
TSNode ts_node_make(const TSTree *, size_t character, size_t byte, size_t row);
|
||||
TSNode ts_node_make(const Tree *, size_t character, size_t byte, size_t row);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ typedef struct {
|
|||
StackSlice slice;
|
||||
} Reduction;
|
||||
|
||||
static void parser__push(Parser *self, StackVersion version, TSTree *tree,
|
||||
static void parser__push(Parser *self, StackVersion version, Tree *tree,
|
||||
TSStateId state) {
|
||||
ts_stack_push(self->stack, version, tree, false, state);
|
||||
ts_tree_release(tree);
|
||||
|
|
@ -78,10 +78,10 @@ static bool parser__breakdown_top_of_stack(Parser *self, StackVersion version) {
|
|||
for (size_t i = 0; i < pop.slices.size; i++) {
|
||||
StackSlice slice = pop.slices.contents[i];
|
||||
TSStateId state = ts_stack_top_state(self->stack, slice.version);
|
||||
TSTree *parent = *array_front(&slice.trees);
|
||||
Tree *parent = *array_front(&slice.trees);
|
||||
|
||||
for (size_t j = 0; j < parent->child_count; j++) {
|
||||
TSTree *child = parent->children[j];
|
||||
Tree *child = parent->children[j];
|
||||
pending = child->child_count > 0;
|
||||
|
||||
if (child->symbol == ts_builtin_sym_error) {
|
||||
|
|
@ -98,7 +98,7 @@ static bool parser__breakdown_top_of_stack(Parser *self, StackVersion version) {
|
|||
}
|
||||
|
||||
for (size_t j = 1; j < slice.trees.size; j++) {
|
||||
TSTree *tree = slice.trees.contents[j];
|
||||
Tree *tree = slice.trees.contents[j];
|
||||
parser__push(self, slice.version, tree, state);
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ static bool parser__breakdown_top_of_stack(Parser *self, StackVersion version) {
|
|||
static void parser__pop_reusable_node(ReusableNode *reusable_node) {
|
||||
reusable_node->byte_index += ts_tree_total_bytes(reusable_node->tree);
|
||||
while (reusable_node->tree) {
|
||||
TSTree *parent = reusable_node->tree->context.parent;
|
||||
Tree *parent = reusable_node->tree->context.parent;
|
||||
size_t next_index = reusable_node->tree->context.index + 1;
|
||||
if (parent && parent->child_count > next_index) {
|
||||
reusable_node->tree = parent->children[next_index];
|
||||
|
|
@ -137,7 +137,7 @@ static bool parser__breakdown_reusable_node(ReusableNode *reusable_node) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool parser__breakdown_lookahead(Parser *self, TSTree **lookahead,
|
||||
static bool parser__breakdown_lookahead(Parser *self, Tree **lookahead,
|
||||
TSStateId state,
|
||||
ReusableNode *reusable_node) {
|
||||
bool result = false;
|
||||
|
|
@ -165,7 +165,7 @@ static void parser__pop_reusable_node_leaf(ReusableNode *reusable_node) {
|
|||
parser__pop_reusable_node(reusable_node);
|
||||
}
|
||||
|
||||
static bool parser__can_reuse(Parser *self, TSStateId state, TSTree *tree,
|
||||
static bool parser__can_reuse(Parser *self, TSStateId state, Tree *tree,
|
||||
TableEntry *table_entry) {
|
||||
if (tree->first_leaf.lex_state == self->language->lex_states[state])
|
||||
return true;
|
||||
|
|
@ -214,15 +214,15 @@ static bool parser__condense_stack(Parser *self) {
|
|||
return result;
|
||||
}
|
||||
|
||||
static TSTree *parser__lex(Parser *self, TSStateId parse_state) {
|
||||
static Tree *parser__lex(Parser *self, TSStateId parse_state) {
|
||||
TSStateId start_state = self->language->lex_states[parse_state];
|
||||
TSStateId current_state = start_state;
|
||||
TSLength start_position = self->lexer.current_position;
|
||||
Length start_position = self->lexer.current_position;
|
||||
LOG("lex state:%d", start_state);
|
||||
|
||||
bool skipped_error = false;
|
||||
int32_t first_error_character = 0;
|
||||
TSLength error_start_position, error_end_position;
|
||||
Length error_start_position, error_end_position;
|
||||
|
||||
ts_lexer_start(&self->lexer, start_state);
|
||||
|
||||
|
|
@ -252,18 +252,18 @@ static TSTree *parser__lex(Parser *self, TSStateId parse_state) {
|
|||
error_end_position = self->lexer.current_position;
|
||||
}
|
||||
|
||||
TSTree *result;
|
||||
Tree *result;
|
||||
|
||||
if (skipped_error) {
|
||||
TSLength padding = ts_length_sub(error_start_position, start_position);
|
||||
TSLength size = ts_length_sub(error_end_position, error_start_position);
|
||||
Length padding = length_sub(error_start_position, start_position);
|
||||
Length size = length_sub(error_end_position, error_start_position);
|
||||
ts_lexer_reset(&self->lexer, error_end_position);
|
||||
result = ts_tree_make_error(size, padding, first_error_character);
|
||||
} else {
|
||||
TSSymbol symbol = self->lexer.data.result_symbol;
|
||||
TSLength padding =
|
||||
ts_length_sub(self->lexer.token_start_position, start_position);
|
||||
TSLength size = ts_length_sub(self->lexer.current_position,
|
||||
Length padding =
|
||||
length_sub(self->lexer.token_start_position, start_position);
|
||||
Length size = length_sub(self->lexer.current_position,
|
||||
self->lexer.token_start_position);
|
||||
result =
|
||||
ts_tree_make_leaf(symbol, padding, size,
|
||||
|
|
@ -283,9 +283,9 @@ static void parser__clear_cached_token(Parser *self) {
|
|||
self->cached_token = NULL;
|
||||
}
|
||||
|
||||
static TSTree *parser__get_lookahead(Parser *self, StackVersion version,
|
||||
static Tree *parser__get_lookahead(Parser *self, StackVersion version,
|
||||
ReusableNode *reusable_node) {
|
||||
TSLength position = ts_stack_top_position(self->stack, version);
|
||||
Length position = ts_stack_top_position(self->stack, version);
|
||||
|
||||
while (reusable_node->tree) {
|
||||
if (reusable_node->byte_index > position.bytes) {
|
||||
|
|
@ -323,7 +323,7 @@ static TSTree *parser__get_lookahead(Parser *self, StackVersion version,
|
|||
continue;
|
||||
}
|
||||
|
||||
TSTree *result = reusable_node->tree;
|
||||
Tree *result = reusable_node->tree;
|
||||
ts_tree_retain(result);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -338,7 +338,7 @@ static TSTree *parser__get_lookahead(Parser *self, StackVersion version,
|
|||
return parser__lex(self, parse_state);
|
||||
}
|
||||
|
||||
static bool parser__select_tree(Parser *self, TSTree *left, TSTree *right) {
|
||||
static bool parser__select_tree(Parser *self, Tree *left, Tree *right) {
|
||||
if (!left)
|
||||
return true;
|
||||
if (!right)
|
||||
|
|
@ -397,7 +397,7 @@ static bool parser__better_version_exists(Parser *self, StackVersion version,
|
|||
}
|
||||
|
||||
static void parser__shift(Parser *self, StackVersion version, TSStateId state,
|
||||
TSTree *lookahead, bool extra) {
|
||||
Tree *lookahead, bool extra) {
|
||||
if (extra != lookahead->extra) {
|
||||
TSSymbolMetadata metadata =
|
||||
ts_language_symbol_metadata(self->language, lookahead->symbol);
|
||||
|
|
@ -416,8 +416,8 @@ static void parser__shift(Parser *self, StackVersion version, TSStateId state,
|
|||
ts_tree_release(lookahead);
|
||||
}
|
||||
|
||||
static bool parser__switch_children(Parser *self, TSTree *tree,
|
||||
TSTree **children, size_t count) {
|
||||
static bool parser__switch_children(Parser *self, Tree *tree,
|
||||
Tree **children, size_t count) {
|
||||
self->scratch_tree.symbol = tree->symbol;
|
||||
self->scratch_tree.child_count = 0;
|
||||
ts_tree_set_children(&self->scratch_tree, count, children);
|
||||
|
|
@ -454,7 +454,7 @@ static Reduction parser__reduce(Parser *self, StackVersion version,
|
|||
while (child_count > 0 && slice.trees.contents[child_count - 1]->extra)
|
||||
child_count--;
|
||||
|
||||
TSTree *parent =
|
||||
Tree *parent =
|
||||
ts_tree_make_node(symbol, child_count, slice.trees.contents, metadata);
|
||||
|
||||
while (i + 1 < pop.slices.size) {
|
||||
|
|
@ -498,7 +498,7 @@ static Reduction parser__reduce(Parser *self, StackVersion version,
|
|||
|
||||
ts_stack_push(self->stack, other_version, parent, false, ERROR_STATE);
|
||||
for (size_t j = parent->child_count; j < slice.trees.size; j++) {
|
||||
TSTree *tree = slice.trees.contents[j];
|
||||
Tree *tree = slice.trees.contents[j];
|
||||
ts_stack_push(self->stack, other_version, tree, false, ERROR_STATE);
|
||||
}
|
||||
|
||||
|
|
@ -510,7 +510,7 @@ static Reduction parser__reduce(Parser *self, StackVersion version,
|
|||
|
||||
parser__push(self, slice.version, parent, action->params.to_state);
|
||||
for (size_t j = parent->child_count; j < slice.trees.size; j++) {
|
||||
TSTree *tree = slice.trees.contents[j];
|
||||
Tree *tree = slice.trees.contents[j];
|
||||
parser__push(self, slice.version, tree, action->params.to_state);
|
||||
}
|
||||
}
|
||||
|
|
@ -539,7 +539,7 @@ static inline const TSParseAction *parser__reductions_after_sequence(
|
|||
for (size_t i = 0; i < trees_below->size; i++) {
|
||||
if (child_count == tree_count_below)
|
||||
break;
|
||||
TSTree *tree = trees_below->contents[trees_below->size - 1 - i];
|
||||
Tree *tree = trees_below->contents[trees_below->size - 1 - i];
|
||||
const TSParseAction *action =
|
||||
ts_language_last_action(self->language, state, tree->symbol);
|
||||
if (!action || action->type != TSParseActionTypeShift)
|
||||
|
|
@ -551,7 +551,7 @@ static inline const TSParseAction *parser__reductions_after_sequence(
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < trees_above->size; i++) {
|
||||
TSTree *tree = trees_above->contents[i];
|
||||
Tree *tree = trees_above->contents[i];
|
||||
const TSParseAction *action =
|
||||
ts_language_last_action(self->language, state, tree->symbol);
|
||||
if (!action || action->type != TSParseActionTypeShift)
|
||||
|
|
@ -704,7 +704,7 @@ static bool parser__repair_error(Parser *self, StackSlice slice,
|
|||
for (size_t i = count_below; i < children.size; i++)
|
||||
array_push(&skipped_children, children.contents[i]);
|
||||
|
||||
TSTree *error = ts_tree_make_error_node(&skipped_children);
|
||||
Tree *error = ts_tree_make_error_node(&skipped_children);
|
||||
children.size = count_below;
|
||||
array_push(&children, error);
|
||||
|
||||
|
|
@ -712,7 +712,7 @@ static bool parser__repair_error(Parser *self, StackSlice slice,
|
|||
array_push(&children, slice.trees.contents[i]);
|
||||
array_delete(&slice.trees);
|
||||
|
||||
TSTree *parent =
|
||||
Tree *parent =
|
||||
ts_tree_make_node(symbol, children.size, children.contents,
|
||||
ts_language_symbol_metadata(self->language, symbol));
|
||||
parser__push(self, slice.version, parent, next_state);
|
||||
|
|
@ -730,7 +730,7 @@ static bool parser__repair_error(Parser *self, StackSlice slice,
|
|||
}
|
||||
}
|
||||
|
||||
static void parser__start(Parser *self, TSInput input, TSTree *previous_tree) {
|
||||
static void parser__start(Parser *self, TSInput input, Tree *previous_tree) {
|
||||
if (previous_tree) {
|
||||
LOG("parse_after_edit");
|
||||
} else {
|
||||
|
|
@ -745,7 +745,7 @@ static void parser__start(Parser *self, TSInput input, TSTree *previous_tree) {
|
|||
}
|
||||
|
||||
static void parser__accept(Parser *self, StackVersion version,
|
||||
TSTree *lookahead) {
|
||||
Tree *lookahead) {
|
||||
lookahead->extra = true;
|
||||
assert(lookahead->symbol == ts_builtin_sym_end);
|
||||
ts_stack_push(self->stack, version, lookahead, false, 1);
|
||||
|
|
@ -755,13 +755,13 @@ static void parser__accept(Parser *self, StackVersion version,
|
|||
StackSlice slice = pop.slices.contents[i];
|
||||
TreeArray trees = slice.trees;
|
||||
|
||||
TSTree *root = NULL;
|
||||
Tree *root = NULL;
|
||||
if (trees.size == 1) {
|
||||
root = trees.contents[0];
|
||||
array_delete(&trees);
|
||||
} else {
|
||||
for (size_t j = trees.size - 1; j + 1 > 0; j--) {
|
||||
TSTree *child = trees.contents[j];
|
||||
Tree *child = trees.contents[j];
|
||||
if (!child->extra) {
|
||||
root = ts_tree_make_copy(child);
|
||||
root->child_count = 0;
|
||||
|
|
@ -881,7 +881,7 @@ static void parser__repair_consumed_error(Parser *self, StackVersion version,
|
|||
}
|
||||
|
||||
last_slice_version = slice.version;
|
||||
TSTree *error = ts_tree_make_error_node(&slice.trees);
|
||||
Tree *error = ts_tree_make_error_node(&slice.trees);
|
||||
error->extra = true;
|
||||
TSStateId state = ts_stack_top_state(self->stack, slice.version);
|
||||
parser__push(self, slice.version, error, state);
|
||||
|
|
@ -920,11 +920,11 @@ static void parser__handle_error(Parser *self, StackVersion version,
|
|||
}
|
||||
|
||||
static void parser__recover(Parser *self, StackVersion version, TSStateId state,
|
||||
TSTree *lookahead) {
|
||||
Tree *lookahead) {
|
||||
if (lookahead->symbol == ts_builtin_sym_end) {
|
||||
LOG("recover_eof");
|
||||
TreeArray children = array_new();
|
||||
TSTree *parent = ts_tree_make_error_node(&children);
|
||||
Tree *parent = ts_tree_make_error_node(&children);
|
||||
parser__push(self, version, parent, 1);
|
||||
parser__accept(self, version, lookahead);
|
||||
}
|
||||
|
|
@ -948,7 +948,7 @@ static void parser__recover(Parser *self, StackVersion version, TSStateId state,
|
|||
static void parser__advance(Parser *self, StackVersion version,
|
||||
ReusableNode *reusable_node) {
|
||||
bool validated_lookahead = false;
|
||||
TSTree *lookahead = parser__get_lookahead(self, version, reusable_node);
|
||||
Tree *lookahead = parser__get_lookahead(self, version, reusable_node);
|
||||
|
||||
for (;;) {
|
||||
TSStateId state = ts_stack_top_state(self->stack, version);
|
||||
|
|
@ -1117,7 +1117,7 @@ void parser_destroy(Parser *self) {
|
|||
array_delete(&self->tree_path2);
|
||||
}
|
||||
|
||||
TSTree *parser_parse(Parser *self, TSInput input, TSTree *old_tree) {
|
||||
Tree *parser_parse(Parser *self, TSInput input, Tree *old_tree) {
|
||||
parser__start(self, input, old_tree);
|
||||
|
||||
StackVersion version = STACK_VERSION_NONE;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ extern "C" {
|
|||
#include "runtime/reduce_action.h"
|
||||
|
||||
typedef struct {
|
||||
TSTree *tree;
|
||||
Tree *tree;
|
||||
size_t byte_index;
|
||||
} ReusableNode;
|
||||
|
||||
|
|
@ -20,11 +20,11 @@ typedef struct {
|
|||
Stack *stack;
|
||||
const TSLanguage *language;
|
||||
ReduceActionSet reduce_actions;
|
||||
TSTree *finished_tree;
|
||||
Tree *finished_tree;
|
||||
bool is_split;
|
||||
bool print_debugging_graphs;
|
||||
TSTree scratch_tree;
|
||||
TSTree *cached_token;
|
||||
Tree scratch_tree;
|
||||
Tree *cached_token;
|
||||
size_t cached_token_byte_index;
|
||||
ReusableNode reusable_node;
|
||||
TreePath tree_path1;
|
||||
|
|
@ -33,7 +33,7 @@ typedef struct {
|
|||
|
||||
bool parser_init(Parser *);
|
||||
void parser_destroy(Parser *);
|
||||
TSTree *parser_parse(Parser *, TSInput, TSTree *);
|
||||
Tree *parser_parse(Parser *, TSInput, Tree *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,40 +3,40 @@
|
|||
|
||||
#include "tree_sitter/runtime.h"
|
||||
|
||||
static inline TSPoint ts_point_add(TSPoint a, TSPoint b) {
|
||||
static inline TSPoint point_add(TSPoint a, TSPoint b) {
|
||||
if (b.row > 0)
|
||||
return (TSPoint){a.row + b.row, b.column};
|
||||
else
|
||||
return (TSPoint){a.row, a.column + b.column};
|
||||
}
|
||||
|
||||
static inline TSPoint ts_point_sub(TSPoint a, TSPoint b) {
|
||||
static inline TSPoint point_sub(TSPoint a, TSPoint b) {
|
||||
if (a.row > b.row)
|
||||
return (TSPoint){a.row - b.row, a.column};
|
||||
else
|
||||
return (TSPoint){0, a.column - b.column};
|
||||
}
|
||||
|
||||
static inline bool ts_point_lte(TSPoint a, TSPoint b) {
|
||||
static inline bool point_lte(TSPoint a, TSPoint b) {
|
||||
return (a.row < b.row) || (a.row == b.row && a.column <= b.column);
|
||||
}
|
||||
|
||||
static inline bool ts_point_lt(TSPoint a, TSPoint b) {
|
||||
static inline bool point_lt(TSPoint a, TSPoint b) {
|
||||
return (a.row < b.row) || (a.row == b.row && a.column < b.column);
|
||||
}
|
||||
|
||||
static inline bool ts_point_eq(TSPoint a, TSPoint b) {
|
||||
static inline bool point_eq(TSPoint a, TSPoint b) {
|
||||
return a.row == b.row && a.column == b.column;
|
||||
}
|
||||
|
||||
static inline TSPoint ts_point_min(TSPoint a, TSPoint b) {
|
||||
static inline TSPoint point_min(TSPoint a, TSPoint b) {
|
||||
if (a.row < b.row || (a.row == b.row && a.column < b.column))
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
}
|
||||
|
||||
static inline TSPoint ts_point_max(TSPoint a, TSPoint b) {
|
||||
static inline TSPoint point_max(TSPoint a, TSPoint b) {
|
||||
if (a.row > b.row || (a.row == b.row && a.column > b.column))
|
||||
return a;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ typedef struct StackNode StackNode;
|
|||
|
||||
typedef struct {
|
||||
StackNode *node;
|
||||
TSTree *tree;
|
||||
Tree *tree;
|
||||
unsigned push_count;
|
||||
bool is_pending;
|
||||
} StackLink;
|
||||
|
||||
struct StackNode {
|
||||
TSStateId state;
|
||||
TSLength position;
|
||||
Length position;
|
||||
StackLink links[MAX_LINK_COUNT];
|
||||
short unsigned int link_count;
|
||||
short unsigned int ref_count;
|
||||
|
|
@ -87,8 +87,8 @@ static void stack_node_release(StackNode *self, StackNodeArray *pool) {
|
|||
}
|
||||
}
|
||||
|
||||
static StackNode *stack_node_new(StackNode *next, TSTree *tree, bool is_pending,
|
||||
TSStateId state, TSLength position,
|
||||
static StackNode *stack_node_new(StackNode *next, Tree *tree, bool is_pending,
|
||||
TSStateId state, Length position,
|
||||
StackNodeArray *pool) {
|
||||
StackNode *node;
|
||||
if (pool->size > 0)
|
||||
|
|
@ -286,7 +286,7 @@ Stack *ts_stack_new() {
|
|||
array_grow(&self->node_pool, MAX_NODE_POOL_SIZE);
|
||||
|
||||
self->base_node =
|
||||
stack_node_new(NULL, NULL, false, 1, ts_length_zero(), &self->node_pool);
|
||||
stack_node_new(NULL, NULL, false, 1, length_zero(), &self->node_pool);
|
||||
stack_node_retain(self->base_node);
|
||||
array_push(&self->heads, ((StackHead){ self->base_node, false, 0 }));
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ TSStateId ts_stack_top_state(const Stack *self, StackVersion version) {
|
|||
return array_get(&self->heads, version)->node->state;
|
||||
}
|
||||
|
||||
TSLength ts_stack_top_position(const Stack *self, StackVersion version) {
|
||||
Length ts_stack_top_position(const Stack *self, StackVersion version) {
|
||||
return array_get(&self->heads, version)->node->position;
|
||||
}
|
||||
|
||||
|
|
@ -346,13 +346,13 @@ unsigned ts_stack_error_count(const Stack *self, StackVersion version) {
|
|||
return node->error_count;
|
||||
}
|
||||
|
||||
bool ts_stack_push(Stack *self, StackVersion version, TSTree *tree,
|
||||
bool ts_stack_push(Stack *self, StackVersion version, Tree *tree,
|
||||
bool is_pending, TSStateId state) {
|
||||
StackHead *head = array_get(&self->heads, version);
|
||||
StackNode *node = head->node;
|
||||
TSLength position = node->position;
|
||||
Length position = node->position;
|
||||
if (tree)
|
||||
position = ts_length_add(position, ts_tree_total_size(tree));
|
||||
position = length_add(position, ts_tree_total_size(tree));
|
||||
StackNode *new_node =
|
||||
stack_node_new(node, tree, is_pending, state, position, &self->node_pool);
|
||||
if (!new_node)
|
||||
|
|
|
|||
|
|
@ -71,13 +71,13 @@ void ts_stack_decrease_push_count(const Stack *, StackVersion, unsigned);
|
|||
* Get the position at the top of the given version of the stack. If the stack
|
||||
* is empty, this returns zero.
|
||||
*/
|
||||
TSLength ts_stack_top_position(const Stack *, StackVersion);
|
||||
Length ts_stack_top_position(const Stack *, StackVersion);
|
||||
|
||||
/*
|
||||
* Push a tree and state onto the given head of the stack. This could cause
|
||||
* the version to merge with an existing version.
|
||||
*/
|
||||
bool ts_stack_push(Stack *, StackVersion, TSTree *, bool, TSStateId);
|
||||
bool ts_stack_push(Stack *, StackVersion, Tree *, bool, TSStateId);
|
||||
|
||||
/*
|
||||
* Pop the given number of entries from the given version of the stack. This
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
TSStateId TS_TREE_STATE_NONE = USHRT_MAX;
|
||||
|
||||
TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size,
|
||||
Tree *ts_tree_make_leaf(TSSymbol sym, Length padding, Length size,
|
||||
TSSymbolMetadata metadata) {
|
||||
TSTree *result = ts_malloc(sizeof(TSTree));
|
||||
*result = (TSTree){
|
||||
Tree *result = ts_malloc(sizeof(Tree));
|
||||
*result = (Tree){
|
||||
.ref_count = 1,
|
||||
.symbol = sym,
|
||||
.size = size,
|
||||
|
|
@ -31,10 +31,10 @@ TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size,
|
|||
}
|
||||
|
||||
bool ts_tree_array_copy(TreeArray self, TreeArray *dest) {
|
||||
TSTree **contents = NULL;
|
||||
Tree **contents = NULL;
|
||||
if (self.capacity > 0) {
|
||||
contents = ts_calloc(self.capacity, sizeof(TSTree *));
|
||||
memcpy(contents, self.contents, self.size * sizeof(TSTree *));
|
||||
contents = ts_calloc(self.capacity, sizeof(Tree *));
|
||||
memcpy(contents, self.contents, self.size * sizeof(Tree *));
|
||||
for (size_t i = 0; i < self.size; i++)
|
||||
ts_tree_retain(contents[i]);
|
||||
}
|
||||
|
|
@ -54,15 +54,15 @@ void ts_tree_array_delete(TreeArray *self) {
|
|||
size_t ts_tree_array_essential_count(const TreeArray *self) {
|
||||
size_t result = 0;
|
||||
for (size_t i = 0; i < self->size; i++) {
|
||||
TSTree *tree = self->contents[i];
|
||||
Tree *tree = self->contents[i];
|
||||
if (!tree->extra && tree->symbol != ts_builtin_sym_error)
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_char) {
|
||||
TSTree *result = ts_tree_make_leaf(ts_builtin_sym_error, padding, size,
|
||||
Tree *ts_tree_make_error(Length size, Length padding, char lookahead_char) {
|
||||
Tree *result = ts_tree_make_leaf(ts_builtin_sym_error, padding, size,
|
||||
(TSSymbolMetadata){
|
||||
.visible = true, .named = true,
|
||||
});
|
||||
|
|
@ -72,34 +72,34 @@ TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_char)
|
|||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_copy(TSTree *self) {
|
||||
TSTree *result = ts_malloc(sizeof(TSTree));
|
||||
Tree *ts_tree_make_copy(Tree *self) {
|
||||
Tree *result = ts_malloc(sizeof(Tree));
|
||||
*result = *self;
|
||||
result->ref_count = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ts_tree_assign_parents(TSTree *self, TreePath *path) {
|
||||
void ts_tree_assign_parents(Tree *self, TreePath *path) {
|
||||
array_clear(path);
|
||||
array_push(path, ((TreePathEntry){self, ts_length_zero(), 0}));
|
||||
array_push(path, ((TreePathEntry){self, length_zero(), 0}));
|
||||
while (path->size > 0) {
|
||||
TSTree *tree = array_pop(path).tree;
|
||||
TSLength offset = ts_length_zero();
|
||||
Tree *tree = array_pop(path).tree;
|
||||
Length offset = length_zero();
|
||||
for (size_t i = 0; i < tree->child_count; i++) {
|
||||
TSTree *child = tree->children[i];
|
||||
Tree *child = tree->children[i];
|
||||
if (child->context.parent != tree || child->context.index != i) {
|
||||
child->context.parent = tree;
|
||||
child->context.index = i;
|
||||
child->context.offset = offset;
|
||||
array_push(path, ((TreePathEntry){child, ts_length_zero(), 0}));
|
||||
array_push(path, ((TreePathEntry){child, length_zero(), 0}));
|
||||
}
|
||||
offset = ts_length_add(offset, ts_tree_total_size(child));
|
||||
offset = length_add(offset, ts_tree_total_size(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) {
|
||||
void ts_tree_set_children(Tree *self, size_t child_count, Tree **children) {
|
||||
if (self->child_count > 0)
|
||||
ts_free(self->children);
|
||||
|
||||
|
|
@ -110,13 +110,13 @@ void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) {
|
|||
self->error_cost = 0;
|
||||
|
||||
for (size_t i = 0; i < child_count; i++) {
|
||||
TSTree *child = children[i];
|
||||
Tree *child = children[i];
|
||||
|
||||
if (i == 0) {
|
||||
self->padding = child->padding;
|
||||
self->size = child->size;
|
||||
} else {
|
||||
self->size = ts_length_add(self->size, ts_tree_total_size(child));
|
||||
self->size = length_add(self->size, ts_tree_total_size(child));
|
||||
}
|
||||
|
||||
self->error_cost += child->error_cost;
|
||||
|
|
@ -153,17 +153,17 @@ void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) {
|
|||
}
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
|
||||
TSTree **children, TSSymbolMetadata metadata) {
|
||||
TSTree *result =
|
||||
ts_tree_make_leaf(symbol, ts_length_zero(), ts_length_zero(), metadata);
|
||||
Tree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
|
||||
Tree **children, TSSymbolMetadata metadata) {
|
||||
Tree *result =
|
||||
ts_tree_make_leaf(symbol, length_zero(), length_zero(), metadata);
|
||||
ts_tree_set_children(result, child_count, children);
|
||||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_error_node(TreeArray *children) {
|
||||
Tree *ts_tree_make_error_node(TreeArray *children) {
|
||||
for (size_t i = 0; i < children->size; i++) {
|
||||
TSTree *child = children->contents[i];
|
||||
Tree *child = children->contents[i];
|
||||
if (child->symbol == ts_builtin_sym_error && child->child_count > 0) {
|
||||
array_splice(children, i, 1, child->child_count, child->children);
|
||||
i += child->child_count - 1;
|
||||
|
|
@ -173,7 +173,7 @@ TSTree *ts_tree_make_error_node(TreeArray *children) {
|
|||
}
|
||||
}
|
||||
|
||||
TSTree *result = ts_tree_make_node(
|
||||
Tree *result = ts_tree_make_node(
|
||||
ts_builtin_sym_error, children->size, children->contents,
|
||||
(TSSymbolMetadata){.extra = false, .visible = true, .named = true });
|
||||
|
||||
|
|
@ -182,12 +182,12 @@ TSTree *ts_tree_make_error_node(TreeArray *children) {
|
|||
return result;
|
||||
}
|
||||
|
||||
void ts_tree_retain(TSTree *self) {
|
||||
void ts_tree_retain(Tree *self) {
|
||||
assert(self->ref_count > 0);
|
||||
self->ref_count++;
|
||||
}
|
||||
|
||||
void ts_tree_release(TSTree *self) {
|
||||
void ts_tree_release(Tree *self) {
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ recur:
|
|||
if (self->child_count > 0) {
|
||||
for (size_t i = 0; i < self->child_count - 1; i++)
|
||||
ts_tree_release(self->children[i]);
|
||||
TSTree *last_child = self->children[self->child_count - 1];
|
||||
Tree *last_child = self->children[self->child_count - 1];
|
||||
ts_free(self->children);
|
||||
ts_free(self);
|
||||
|
||||
|
|
@ -211,11 +211,11 @@ recur:
|
|||
}
|
||||
}
|
||||
|
||||
size_t ts_tree_start_column(const TSTree *self) {
|
||||
size_t ts_tree_start_column(const Tree *self) {
|
||||
size_t column = self->padding.extent.column;
|
||||
if (self->padding.extent.row > 0)
|
||||
return column;
|
||||
for (const TSTree *tree = self; tree != NULL; tree = tree->context.parent) {
|
||||
for (const Tree *tree = self; tree != NULL; tree = tree->context.parent) {
|
||||
column += tree->context.offset.extent.column;
|
||||
if (tree->context.offset.extent.row > 0)
|
||||
break;
|
||||
|
|
@ -223,14 +223,14 @@ size_t ts_tree_start_column(const TSTree *self) {
|
|||
return column;
|
||||
}
|
||||
|
||||
size_t ts_tree_end_column(const TSTree *self) {
|
||||
size_t ts_tree_end_column(const Tree *self) {
|
||||
size_t result = self->size.extent.column;
|
||||
if (self->size.extent.row == 0)
|
||||
result += ts_tree_start_column(self);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ts_tree_eq(const TSTree *self, const TSTree *other) {
|
||||
bool ts_tree_eq(const Tree *self, const Tree *other) {
|
||||
if (self) {
|
||||
if (!other)
|
||||
return false;
|
||||
|
|
@ -258,7 +258,7 @@ bool ts_tree_eq(const TSTree *self, const TSTree *other) {
|
|||
return true;
|
||||
}
|
||||
|
||||
int ts_tree_compare(const TSTree *left, const TSTree *right) {
|
||||
int ts_tree_compare(const Tree *left, const Tree *right) {
|
||||
if (left->symbol < right->symbol)
|
||||
return -1;
|
||||
if (right->symbol < left->symbol)
|
||||
|
|
@ -268,8 +268,8 @@ int ts_tree_compare(const TSTree *left, const TSTree *right) {
|
|||
if (right->child_count < left->child_count)
|
||||
return 1;
|
||||
for (size_t i = 0; i < left->child_count; i++) {
|
||||
TSTree *left_child = left->children[i];
|
||||
TSTree *right_child = right->children[i];
|
||||
Tree *left_child = left->children[i];
|
||||
Tree *right_child = right->children[i];
|
||||
switch (ts_tree_compare(left_child, right_child)) {
|
||||
case -1:
|
||||
return -1;
|
||||
|
|
@ -287,70 +287,70 @@ static inline long min(long a, long b) {
|
|||
}
|
||||
|
||||
|
||||
void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
|
||||
void ts_tree_edit(Tree *self, const TSInputEdit *edit) {
|
||||
size_t old_end_byte = edit->start_byte + edit->bytes_removed;
|
||||
size_t new_end_byte = edit->start_byte + edit->bytes_added;
|
||||
TSPoint old_end_point = ts_point_add(edit->start_point, edit->extent_removed);
|
||||
TSPoint new_end_point = ts_point_add(edit->start_point, edit->extent_added);
|
||||
TSPoint old_end_point = point_add(edit->start_point, edit->extent_removed);
|
||||
TSPoint new_end_point = point_add(edit->start_point, edit->extent_added);
|
||||
|
||||
assert(old_end_byte <= ts_tree_total_bytes(self));
|
||||
|
||||
self->has_changes = true;
|
||||
|
||||
if (edit->start_byte < self->padding.bytes) {
|
||||
ts_length_set_unknown_chars(&self->padding);
|
||||
length_set_unknown_chars(&self->padding);
|
||||
if (self->padding.bytes >= old_end_byte) {
|
||||
size_t trailing_padding_bytes = self->padding.bytes - old_end_byte;
|
||||
TSPoint trailing_padding_extent = ts_point_sub(self->padding.extent, old_end_point);
|
||||
TSPoint trailing_padding_extent = point_sub(self->padding.extent, old_end_point);
|
||||
self->padding.bytes = new_end_byte + trailing_padding_bytes;
|
||||
self->padding.extent = ts_point_add(new_end_point, trailing_padding_extent);
|
||||
self->padding.extent = point_add(new_end_point, trailing_padding_extent);
|
||||
} else {
|
||||
ts_length_set_unknown_chars(&self->size);
|
||||
length_set_unknown_chars(&self->size);
|
||||
size_t removed_content_bytes = old_end_byte - self->padding.bytes;
|
||||
TSPoint removed_content_extent = ts_point_sub(old_end_point, self->padding.extent);
|
||||
TSPoint removed_content_extent = point_sub(old_end_point, self->padding.extent);
|
||||
self->size.bytes = self->size.bytes - removed_content_bytes;
|
||||
self->size.extent = ts_point_sub(self->size.extent, removed_content_extent);
|
||||
self->size.extent = point_sub(self->size.extent, removed_content_extent);
|
||||
self->padding.bytes = new_end_byte;
|
||||
self->padding.extent = new_end_point;
|
||||
}
|
||||
} else if (edit->start_byte == self->padding.bytes && edit->bytes_removed == 0) {
|
||||
ts_length_set_unknown_chars(&self->padding);
|
||||
length_set_unknown_chars(&self->padding);
|
||||
self->padding.bytes = self->padding.bytes + edit->bytes_added;
|
||||
self->padding.extent = ts_point_add(self->padding.extent, edit->extent_added);
|
||||
self->padding.extent = point_add(self->padding.extent, edit->extent_added);
|
||||
} else {
|
||||
ts_length_set_unknown_chars(&self->size);
|
||||
length_set_unknown_chars(&self->size);
|
||||
size_t trailing_content_bytes = ts_tree_total_bytes(self) - old_end_byte;
|
||||
TSPoint trailing_content_extent = ts_point_sub(ts_tree_total_extent(self), old_end_point);
|
||||
TSPoint trailing_content_extent = point_sub(ts_tree_total_extent(self), old_end_point);
|
||||
self->size.bytes = new_end_byte + trailing_content_bytes - self->padding.bytes;
|
||||
self->size.extent = ts_point_sub(ts_point_add(new_end_point, trailing_content_extent), self->padding.extent);
|
||||
self->size.extent = point_sub(point_add(new_end_point, trailing_content_extent), self->padding.extent);
|
||||
}
|
||||
|
||||
bool found_first_child = false;
|
||||
long remaining_bytes_to_delete = 0;
|
||||
TSPoint remaining_extent_to_delete = {0, 0};
|
||||
TSLength child_left, child_right = ts_length_zero();
|
||||
Length child_left, child_right = length_zero();
|
||||
for (size_t i = 0; i < self->child_count; i++) {
|
||||
TSTree *child = self->children[i];
|
||||
Tree *child = self->children[i];
|
||||
child_left = child_right;
|
||||
|
||||
if (!found_first_child) {
|
||||
child_right = ts_length_add(child_left, ts_tree_total_size(child));
|
||||
child_right = length_add(child_left, ts_tree_total_size(child));
|
||||
if (child_right.bytes >= edit->start_byte) {
|
||||
found_first_child = true;
|
||||
TSInputEdit child_edit = {
|
||||
.start_byte = edit->start_byte - child_left.bytes,
|
||||
.bytes_added = edit->bytes_added,
|
||||
.bytes_removed = edit->bytes_removed,
|
||||
.start_point = ts_point_sub(edit->start_point, child_left.extent),
|
||||
.start_point = point_sub(edit->start_point, child_left.extent),
|
||||
.extent_added = edit->extent_added,
|
||||
.extent_removed = edit->extent_removed,
|
||||
};
|
||||
|
||||
if (old_end_byte > child_right.bytes) {
|
||||
child_edit.bytes_removed = child_right.bytes - edit->start_byte;
|
||||
child_edit.extent_removed = ts_point_sub(child_right.extent, edit->start_point);
|
||||
child_edit.extent_removed = point_sub(child_right.extent, edit->start_point);
|
||||
remaining_bytes_to_delete = old_end_byte - child_right.bytes;
|
||||
remaining_extent_to_delete = ts_point_sub(old_end_point, child_right.extent);
|
||||
remaining_extent_to_delete = point_sub(old_end_point, child_right.extent);
|
||||
}
|
||||
|
||||
ts_tree_edit(child, &child_edit);
|
||||
|
|
@ -362,14 +362,14 @@ void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
|
|||
.bytes_removed = min(remaining_bytes_to_delete, ts_tree_total_bytes(child)),
|
||||
.start_point = {0, 0},
|
||||
.extent_added = {0, 0},
|
||||
.extent_removed = ts_point_min(remaining_extent_to_delete, ts_tree_total_size(child).extent),
|
||||
.extent_removed = point_min(remaining_extent_to_delete, ts_tree_total_size(child).extent),
|
||||
};
|
||||
remaining_bytes_to_delete -= child_edit.bytes_removed;
|
||||
remaining_extent_to_delete = ts_point_sub(remaining_extent_to_delete, child_edit.extent_removed);
|
||||
remaining_extent_to_delete = point_sub(remaining_extent_to_delete, child_edit.extent_removed);
|
||||
ts_tree_edit(child, &child_edit);
|
||||
}
|
||||
|
||||
child_right = ts_length_add(child_left, ts_tree_total_size(child));
|
||||
child_right = length_add(child_left, ts_tree_total_size(child));
|
||||
child->context.offset = child_left;
|
||||
}
|
||||
}
|
||||
|
|
@ -389,7 +389,7 @@ static size_t ts_tree__write_char_to_string(char *s, size_t n, int32_t c) {
|
|||
return snprintf(s, n, "%d", c);
|
||||
}
|
||||
|
||||
static size_t ts_tree__write_to_string(const TSTree *self,
|
||||
static size_t ts_tree__write_to_string(const Tree *self,
|
||||
const TSLanguage *language, char *string,
|
||||
size_t limit, bool is_root,
|
||||
bool include_all) {
|
||||
|
|
@ -416,7 +416,7 @@ static size_t ts_tree__write_to_string(const TSTree *self,
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < self->child_count; i++) {
|
||||
TSTree *child = self->children[i];
|
||||
Tree *child = self->children[i];
|
||||
cursor += ts_tree__write_to_string(child, language, *writer, limit, false,
|
||||
include_all);
|
||||
}
|
||||
|
|
@ -427,7 +427,7 @@ static size_t ts_tree__write_to_string(const TSTree *self,
|
|||
return cursor - string;
|
||||
}
|
||||
|
||||
char *ts_tree_string(const TSTree *self, const TSLanguage *language,
|
||||
char *ts_tree_string(const Tree *self, const TSLanguage *language,
|
||||
bool include_all) {
|
||||
static char SCRATCH[1];
|
||||
size_t size =
|
||||
|
|
@ -437,7 +437,7 @@ char *ts_tree_string(const TSTree *self, const TSLanguage *language,
|
|||
return result;
|
||||
}
|
||||
|
||||
void ts_tree__print_dot_graph(const TSTree *self, size_t byte_offset,
|
||||
void ts_tree__print_dot_graph(const Tree *self, size_t byte_offset,
|
||||
const TSLanguage *language, FILE *f) {
|
||||
fprintf(f, "tree_%p [label=\"%s\"", self,
|
||||
ts_language_symbol_name(language, self->symbol));
|
||||
|
|
@ -451,14 +451,14 @@ void ts_tree__print_dot_graph(const TSTree *self, size_t byte_offset,
|
|||
byte_offset, byte_offset + ts_tree_total_bytes(self), self->parse_state,
|
||||
self->error_cost);
|
||||
for (size_t i = 0; i < self->child_count; i++) {
|
||||
const TSTree *child = self->children[i];
|
||||
const Tree *child = self->children[i];
|
||||
ts_tree__print_dot_graph(child, byte_offset, language, f);
|
||||
fprintf(f, "tree_%p -> tree_%p [tooltip=%lu]\n", self, child, i);
|
||||
byte_offset += ts_tree_total_bytes(child);
|
||||
}
|
||||
}
|
||||
|
||||
void ts_tree_print_dot_graph(const TSTree *self, const TSLanguage *language,
|
||||
void ts_tree_print_dot_graph(const Tree *self, const TSLanguage *language,
|
||||
FILE *f) {
|
||||
fprintf(f, "digraph tree {\n");
|
||||
fprintf(f, "edge [arrowhead=none]\n");
|
||||
|
|
|
|||
|
|
@ -14,23 +14,23 @@ extern "C" {
|
|||
|
||||
extern TSStateId TS_TREE_STATE_NONE;
|
||||
|
||||
typedef struct TSTree {
|
||||
typedef struct Tree {
|
||||
struct {
|
||||
struct TSTree *parent;
|
||||
struct Tree *parent;
|
||||
size_t index;
|
||||
TSLength offset;
|
||||
Length offset;
|
||||
} context;
|
||||
|
||||
size_t child_count;
|
||||
size_t visible_child_count;
|
||||
size_t named_child_count;
|
||||
union {
|
||||
struct TSTree **children;
|
||||
struct Tree **children;
|
||||
int32_t lookahead_char;
|
||||
};
|
||||
|
||||
TSLength padding;
|
||||
TSLength size;
|
||||
Length padding;
|
||||
Length size;
|
||||
|
||||
TSSymbol symbol;
|
||||
TSStateId parse_state;
|
||||
|
|
@ -48,15 +48,15 @@ typedef struct TSTree {
|
|||
bool fragile_left : 1;
|
||||
bool fragile_right : 1;
|
||||
bool has_changes : 1;
|
||||
} TSTree;
|
||||
} Tree;
|
||||
|
||||
typedef struct {
|
||||
TSTree *tree;
|
||||
TSLength position;
|
||||
Tree *tree;
|
||||
Length position;
|
||||
size_t child_index;
|
||||
} TreePathEntry;
|
||||
|
||||
typedef Array(TSTree *) TreeArray;
|
||||
typedef Array(Tree *) TreeArray;
|
||||
|
||||
typedef Array(TreePathEntry) TreePath;
|
||||
|
||||
|
|
@ -64,41 +64,41 @@ bool ts_tree_array_copy(TreeArray, TreeArray *);
|
|||
void ts_tree_array_delete(TreeArray *);
|
||||
size_t ts_tree_array_essential_count(const TreeArray *);
|
||||
|
||||
TSTree *ts_tree_make_leaf(TSSymbol, TSLength, TSLength, TSSymbolMetadata);
|
||||
TSTree *ts_tree_make_node(TSSymbol, size_t, TSTree **, TSSymbolMetadata);
|
||||
TSTree *ts_tree_make_copy(TSTree *child);
|
||||
TSTree *ts_tree_make_error_node(TreeArray *);
|
||||
TSTree *ts_tree_make_error(TSLength, TSLength, char);
|
||||
void ts_tree_retain(TSTree *tree);
|
||||
void ts_tree_release(TSTree *tree);
|
||||
bool ts_tree_eq(const TSTree *tree1, const TSTree *tree2);
|
||||
int ts_tree_compare(const TSTree *tree1, const TSTree *tree2);
|
||||
Tree *ts_tree_make_leaf(TSSymbol, Length, Length, TSSymbolMetadata);
|
||||
Tree *ts_tree_make_node(TSSymbol, size_t, Tree **, TSSymbolMetadata);
|
||||
Tree *ts_tree_make_copy(Tree *child);
|
||||
Tree *ts_tree_make_error_node(TreeArray *);
|
||||
Tree *ts_tree_make_error(Length, Length, char);
|
||||
void ts_tree_retain(Tree *tree);
|
||||
void ts_tree_release(Tree *tree);
|
||||
bool ts_tree_eq(const Tree *tree1, const Tree *tree2);
|
||||
int ts_tree_compare(const Tree *tree1, const Tree *tree2);
|
||||
|
||||
size_t ts_tree_start_column(const TSTree *self);
|
||||
size_t ts_tree_end_column(const TSTree *self);
|
||||
void ts_tree_set_children(TSTree *, size_t, TSTree **);
|
||||
void ts_tree_assign_parents(TSTree *, TreePath *);
|
||||
void ts_tree_edit(TSTree *, const TSInputEdit *edit);
|
||||
char *ts_tree_string(const TSTree *, const TSLanguage *, bool include_all);
|
||||
void ts_tree_print_dot_graph(const TSTree *, const TSLanguage *, FILE *);
|
||||
size_t ts_tree_start_column(const Tree *self);
|
||||
size_t ts_tree_end_column(const Tree *self);
|
||||
void ts_tree_set_children(Tree *, size_t, Tree **);
|
||||
void ts_tree_assign_parents(Tree *, TreePath *);
|
||||
void ts_tree_edit(Tree *, const TSInputEdit *edit);
|
||||
char *ts_tree_string(const Tree *, const TSLanguage *, bool include_all);
|
||||
void ts_tree_print_dot_graph(const Tree *, const TSLanguage *, FILE *);
|
||||
|
||||
static inline size_t ts_tree_total_chars(const TSTree *self) {
|
||||
static inline size_t ts_tree_total_chars(const Tree *self) {
|
||||
return self->padding.chars + self->size.chars;
|
||||
}
|
||||
|
||||
static inline size_t ts_tree_total_bytes(const TSTree *self) {
|
||||
static inline size_t ts_tree_total_bytes(const Tree *self) {
|
||||
return self->padding.bytes + self->size.bytes;
|
||||
}
|
||||
|
||||
static inline TSLength ts_tree_total_size(const TSTree *self) {
|
||||
return ts_length_add(self->padding, self->size);
|
||||
static inline Length ts_tree_total_size(const Tree *self) {
|
||||
return length_add(self->padding, self->size);
|
||||
}
|
||||
|
||||
static inline TSPoint ts_tree_total_extent(const TSTree *self) {
|
||||
return ts_point_add(self->padding.extent, self->size.extent);
|
||||
static inline TSPoint ts_tree_total_extent(const Tree *self) {
|
||||
return point_add(self->padding.extent, self->size.extent);
|
||||
}
|
||||
|
||||
static inline bool ts_tree_is_fragile(const TSTree *tree) {
|
||||
static inline bool ts_tree_is_fragile(const Tree *tree) {
|
||||
return tree->fragile_left || tree->fragile_right ||
|
||||
ts_tree_total_chars(tree) == 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ typedef Array(TSRange) RangeArray;
|
|||
static void range_array_add(RangeArray *results, TSPoint start, TSPoint end) {
|
||||
if (results->size > 0) {
|
||||
TSRange *last_range = array_back(results);
|
||||
if (ts_point_lte(start, last_range->end)) {
|
||||
if (point_lte(start, last_range->end)) {
|
||||
last_range->end = end;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ts_point_lt(start, end)) {
|
||||
if (point_lt(start, end)) {
|
||||
TSRange range = { start, end };
|
||||
array_push(results, range);
|
||||
}
|
||||
|
|
@ -27,12 +27,12 @@ static bool tree_path_descend(TreePath *path, TSPoint position) {
|
|||
do {
|
||||
did_descend = false;
|
||||
TreePathEntry entry = *array_back(path);
|
||||
TSLength child_position = entry.position;
|
||||
Length child_position = entry.position;
|
||||
for (size_t i = 0; i < entry.tree->child_count; i++) {
|
||||
TSTree *child = entry.tree->children[i];
|
||||
TSLength child_right_position =
|
||||
ts_length_add(child_position, ts_tree_total_size(child));
|
||||
if (ts_point_lt(position, child_right_position.extent)) {
|
||||
Tree *child = entry.tree->children[i];
|
||||
Length child_right_position =
|
||||
length_add(child_position, ts_tree_total_size(child));
|
||||
if (point_lt(position, child_right_position.extent)) {
|
||||
TreePathEntry child_entry = { child, child_position, i };
|
||||
if (child->visible) {
|
||||
array_push(path, child_entry);
|
||||
|
|
@ -58,10 +58,10 @@ static size_t tree_path_advance(TreePath *path) {
|
|||
break;
|
||||
TreePathEntry parent_entry = *array_back(path);
|
||||
if (parent_entry.tree->visible) ascend_count++;
|
||||
TSLength position =
|
||||
ts_length_add(entry.position, ts_tree_total_size(entry.tree));
|
||||
Length position =
|
||||
length_add(entry.position, ts_tree_total_size(entry.tree));
|
||||
for (size_t i = entry.child_index + 1; i < parent_entry.tree->child_count; i++) {
|
||||
TSTree *next_child = parent_entry.tree->children[i];
|
||||
Tree *next_child = parent_entry.tree->children[i];
|
||||
if (next_child->visible || next_child->visible_child_count > 0) {
|
||||
if (parent_entry.tree->visible) ascend_count--;
|
||||
array_push(path, ((TreePathEntry){
|
||||
|
|
@ -73,7 +73,7 @@ static size_t tree_path_advance(TreePath *path) {
|
|||
tree_path_descend(path, (TSPoint){ 0, 0 });
|
||||
return ascend_count;
|
||||
}
|
||||
position = ts_length_add(position, ts_tree_total_size(next_child));
|
||||
position = length_add(position, ts_tree_total_size(next_child));
|
||||
}
|
||||
}
|
||||
return ascend_count;
|
||||
|
|
@ -87,7 +87,7 @@ static void tree_path_ascend(TreePath *path, size_t count) {
|
|||
}
|
||||
}
|
||||
|
||||
static void tree_path_init(TreePath *path, TSTree *tree) {
|
||||
static void tree_path_init(TreePath *path, Tree *tree) {
|
||||
array_clear(path);
|
||||
array_push(path, ((TreePathEntry){
|
||||
.tree = tree,
|
||||
|
|
@ -98,7 +98,7 @@ static void tree_path_init(TreePath *path, TSTree *tree) {
|
|||
tree_path_descend(path, (TSPoint){ 0, 0 });
|
||||
}
|
||||
|
||||
static bool tree_must_eq(TSTree *old_tree, TSTree *new_tree) {
|
||||
static bool tree_must_eq(Tree *old_tree, Tree *new_tree) {
|
||||
return old_tree == new_tree || (
|
||||
!old_tree->has_changes &&
|
||||
old_tree->symbol == new_tree->symbol &&
|
||||
|
|
@ -121,32 +121,32 @@ static void tree_path_get_changes(TreePath *old_path, TreePath *new_path,
|
|||
|
||||
TreePathEntry old_entry = *array_back(old_path);
|
||||
TreePathEntry new_entry = *array_back(new_path);
|
||||
TSTree *old_tree = old_entry.tree;
|
||||
TSTree *new_tree = new_entry.tree;
|
||||
Tree *old_tree = old_entry.tree;
|
||||
Tree *new_tree = new_entry.tree;
|
||||
size_t old_start_byte = old_entry.position.bytes + old_tree->padding.bytes;
|
||||
size_t new_start_byte = new_entry.position.bytes + new_tree->padding.bytes;
|
||||
TSPoint old_start_point =
|
||||
ts_point_add(old_entry.position.extent, old_tree->padding.extent);
|
||||
point_add(old_entry.position.extent, old_tree->padding.extent);
|
||||
TSPoint new_start_point =
|
||||
ts_point_add(new_entry.position.extent, new_tree->padding.extent);
|
||||
TSPoint old_end_point = ts_point_add(old_start_point, old_tree->size.extent);
|
||||
TSPoint new_end_point = ts_point_add(new_start_point, new_tree->size.extent);
|
||||
point_add(new_entry.position.extent, new_tree->padding.extent);
|
||||
TSPoint old_end_point = point_add(old_start_point, old_tree->size.extent);
|
||||
TSPoint new_end_point = point_add(new_start_point, new_tree->size.extent);
|
||||
|
||||
// #define NAME(t) (ts_language_symbol_name(language, ((TSTree *)(t))->symbol))
|
||||
// #define NAME(t) (ts_language_symbol_name(language, ((Tree *)(t))->symbol))
|
||||
// printf("At [%-2lu, %-2lu] Compare (%-20s\t [%-2lu, %-2lu] - [%lu, %lu])\tvs\t(%-20s\t [%lu, %lu] - [%lu, %lu])\n",
|
||||
// position.row, position.column, NAME(old_tree), old_start_point.row,
|
||||
// old_start_point.column, old_end_point.row, old_end_point.column,
|
||||
// NAME(new_tree), new_start_point.row, new_start_point.column,
|
||||
// new_end_point.row, new_end_point.column);
|
||||
|
||||
if (ts_point_lt(position, old_start_point)) {
|
||||
if (ts_point_lt(position, new_start_point)) {
|
||||
next_position = ts_point_min(old_start_point, new_start_point);
|
||||
if (point_lt(position, old_start_point)) {
|
||||
if (point_lt(position, new_start_point)) {
|
||||
next_position = point_min(old_start_point, new_start_point);
|
||||
} else {
|
||||
is_changed = true;
|
||||
next_position = old_start_point;
|
||||
}
|
||||
} else if (ts_point_lt(position, new_start_point)) {
|
||||
} else if (point_lt(position, new_start_point)) {
|
||||
is_changed = true;
|
||||
next_position = new_start_point;
|
||||
} else if (old_start_byte == new_start_byte &&
|
||||
|
|
@ -164,15 +164,15 @@ static void tree_path_get_changes(TreePath *old_path, TreePath *new_path,
|
|||
is_changed = true;
|
||||
next_position = old_end_point;
|
||||
} else {
|
||||
next_position = ts_point_min(old_end_point, new_end_point);
|
||||
next_position = point_min(old_end_point, new_end_point);
|
||||
}
|
||||
} else {
|
||||
is_changed = true;
|
||||
next_position = ts_point_min(old_end_point, new_end_point);
|
||||
next_position = point_min(old_end_point, new_end_point);
|
||||
}
|
||||
|
||||
bool at_old_end = ts_point_lte(old_end_point, next_position);
|
||||
bool at_new_end = ts_point_lte(new_end_point, next_position);
|
||||
bool at_old_end = point_lte(old_end_point, next_position);
|
||||
bool at_new_end = point_lte(new_end_point, next_position);
|
||||
|
||||
if (at_new_end && at_old_end) {
|
||||
size_t old_ascend_count = tree_path_advance(old_path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue