Move ts_tree_compare to the right file
This commit is contained in:
parent
7aba2a0716
commit
5c95d02bd0
3 changed files with 26 additions and 25 deletions
|
|
@ -462,32 +462,8 @@ static ConsumeResult ts_parser__consume_lookahead(TSParser *self, int head) {
|
|||
}
|
||||
}
|
||||
|
||||
static int ts_tree__compare(TSTree *left, TSTree *right) {
|
||||
if (left->symbol < right->symbol)
|
||||
return -1;
|
||||
if (right->symbol < left->symbol)
|
||||
return 1;
|
||||
if (left->child_count < right->child_count)
|
||||
return -1;
|
||||
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];
|
||||
switch (ts_tree__compare(left_child, right_child)) {
|
||||
case -1:
|
||||
return -1;
|
||||
case 1:
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static TSTree *ts_parser__select_tree(void *data, TSTree *left, TSTree *right) {
|
||||
if (ts_tree__compare(left, right) <= 0)
|
||||
if (ts_tree_compare(left, right) <= 0)
|
||||
return left;
|
||||
else
|
||||
return right;
|
||||
|
|
|
|||
|
|
@ -143,6 +143,30 @@ bool ts_tree_eq(const TSTree *self, const TSTree *other) {
|
|||
return true;
|
||||
}
|
||||
|
||||
int ts_tree_compare(const TSTree *left, const TSTree *right) {
|
||||
if (left->symbol < right->symbol)
|
||||
return -1;
|
||||
if (right->symbol < left->symbol)
|
||||
return 1;
|
||||
if (left->child_count < right->child_count)
|
||||
return -1;
|
||||
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];
|
||||
switch (ts_tree_compare(left_child, right_child)) {
|
||||
case -1:
|
||||
return -1;
|
||||
case 1:
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t write_lookahead_to_string(char *string, size_t limit,
|
||||
char lookahead) {
|
||||
switch (lookahead) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_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);
|
||||
char *ts_tree_string(const TSTree *tree, const char **names,
|
||||
bool include_anonymous);
|
||||
TSLength ts_tree_total_size(const TSTree *tree);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue