Rename error_depth -> error_count
This commit is contained in:
parent
1d617ab5e0
commit
52ccebbf80
3 changed files with 28 additions and 28 deletions
|
|
@ -365,7 +365,7 @@ static bool parser__select_tree(Parser *self, TSTree *left, TSTree *right) {
|
|||
}
|
||||
|
||||
static bool parser__better_version_exists(Parser *self, StackVersion version,
|
||||
unsigned my_error_depth,
|
||||
unsigned my_error_count,
|
||||
unsigned my_error_cost) {
|
||||
if (self->finished_tree && self->finished_tree->error_size <= my_error_cost)
|
||||
return true;
|
||||
|
|
@ -375,22 +375,22 @@ static bool parser__better_version_exists(Parser *self, StackVersion version,
|
|||
continue;
|
||||
|
||||
unsigned error_cost = ts_stack_error_cost(self->stack, i);
|
||||
unsigned error_depth = ts_stack_error_depth(self->stack, i);
|
||||
unsigned error_count = ts_stack_error_count(self->stack, i);
|
||||
|
||||
if ((error_depth > my_error_depth + 1) ||
|
||||
(error_depth > my_error_depth && error_cost >= my_error_cost) ||
|
||||
(my_error_depth == 0 && error_cost > my_error_cost) ||
|
||||
(error_depth == my_error_depth &&
|
||||
if ((error_count > my_error_count + 1) ||
|
||||
(error_count > my_error_count && error_cost >= my_error_cost) ||
|
||||
(my_error_count == 0 && error_cost > my_error_cost) ||
|
||||
(error_count == my_error_count &&
|
||||
error_cost >= my_error_cost + ERROR_COST_THRESHOLD)) {
|
||||
LOG("halt_other version:%u", i);
|
||||
ts_stack_halt(self->stack, i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((my_error_depth > error_depth + 1) ||
|
||||
(my_error_depth > error_depth && my_error_cost >= error_cost) ||
|
||||
(error_depth == 0 && my_error_cost > error_cost) ||
|
||||
(my_error_depth == error_depth &&
|
||||
if ((my_error_count > error_count + 1) ||
|
||||
(my_error_count > error_count && my_error_cost >= error_cost) ||
|
||||
(error_count == 0 && my_error_cost > error_cost) ||
|
||||
(my_error_count == error_count &&
|
||||
my_error_cost >= error_cost + ERROR_COST_THRESHOLD)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -516,10 +516,10 @@ static Reduction parser__reduce(Parser *self, StackVersion version,
|
|||
|
||||
if (action->type == TSParseActionTypeRecover && child_count > 1 &&
|
||||
allow_skipping) {
|
||||
unsigned error_depth = ts_stack_error_depth(self->stack, slice.version);
|
||||
unsigned error_count = ts_stack_error_count(self->stack, slice.version);
|
||||
unsigned error_cost =
|
||||
ts_stack_error_cost(self->stack, slice.version) + 1;
|
||||
if (!parser__better_version_exists(self, slice.version, error_depth,
|
||||
if (!parser__better_version_exists(self, slice.version, error_count,
|
||||
error_cost)) {
|
||||
StackVersion other_version =
|
||||
ts_stack_duplicate_version(self->stack, slice.version);
|
||||
|
|
@ -754,8 +754,8 @@ static RepairResult parser__repair_error(Parser *self, StackSlice slice,
|
|||
CHECK(parser__push(self, slice.version, parent, next_state));
|
||||
|
||||
unsigned error_cost = ts_stack_error_cost(self->stack, slice.version);
|
||||
unsigned error_depth = ts_stack_error_depth(self->stack, slice.version);
|
||||
if (parser__better_version_exists(self, slice.version, error_depth,
|
||||
unsigned error_count = ts_stack_error_count(self->stack, slice.version);
|
||||
if (parser__better_version_exists(self, slice.version, error_count,
|
||||
error_cost)) {
|
||||
LOG("no_better_repair_found");
|
||||
ts_stack_halt(self->stack, slice.version);
|
||||
|
|
@ -955,8 +955,8 @@ error:
|
|||
static bool parser__handle_error(Parser *self, StackVersion version,
|
||||
TSSymbol lookahead_symbol) {
|
||||
unsigned error_cost = ts_stack_error_cost(self->stack, version);
|
||||
unsigned error_depth = ts_stack_error_depth(self->stack, version) + 1;
|
||||
if (parser__better_version_exists(self, version, error_depth, error_cost)) {
|
||||
unsigned error_count = ts_stack_error_count(self->stack, version) + 1;
|
||||
if (parser__better_version_exists(self, version, error_count, error_cost)) {
|
||||
ts_stack_halt(self->stack, version);
|
||||
LOG("bail_on_error");
|
||||
return true;
|
||||
|
|
@ -1006,8 +1006,8 @@ static bool parser__recover(Parser *self, StackVersion version, TSStateId state,
|
|||
}
|
||||
|
||||
unsigned error_cost = ts_stack_error_cost(self->stack, version);
|
||||
unsigned error_depth = ts_stack_error_depth(self->stack, version);
|
||||
if (parser__better_version_exists(self, version, error_depth, error_cost)) {
|
||||
unsigned error_count = ts_stack_error_count(self->stack, version);
|
||||
if (parser__better_version_exists(self, version, error_count, error_cost)) {
|
||||
ts_stack_halt(self->stack, version);
|
||||
LOG("bail_on_recovery");
|
||||
return true;
|
||||
|
|
@ -1142,7 +1142,7 @@ static bool parser__advance(Parser *self, StackVersion version,
|
|||
}
|
||||
|
||||
case TSParseActionTypeAccept: {
|
||||
if (ts_stack_error_depth(self->stack, version) > 0)
|
||||
if (ts_stack_error_count(self->stack, version) > 0)
|
||||
continue;
|
||||
|
||||
LOG("accept");
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ struct StackNode {
|
|||
short unsigned int link_count;
|
||||
short unsigned int ref_count;
|
||||
unsigned error_cost;
|
||||
unsigned error_depth;
|
||||
unsigned error_count;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -97,7 +97,7 @@ static StackNode *stack_node_new(StackNode *next, TSTree *tree, bool is_pending,
|
|||
.links = {},
|
||||
.state = state,
|
||||
.position = position,
|
||||
.error_depth = 0,
|
||||
.error_count = 0,
|
||||
.error_cost = 0,
|
||||
};
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ static StackNode *stack_node_new(StackNode *next, TSTree *tree, bool is_pending,
|
|||
node->links[0] = (StackLink){ next, tree, is_pending };
|
||||
|
||||
node->error_cost = next->error_cost;
|
||||
node->error_depth = next->error_depth;
|
||||
node->error_count = next->error_count;
|
||||
|
||||
if (tree) {
|
||||
ts_tree_retain(tree);
|
||||
|
|
@ -121,7 +121,7 @@ static StackNode *stack_node_new(StackNode *next, TSTree *tree, bool is_pending,
|
|||
}
|
||||
} else {
|
||||
node->error_cost++;
|
||||
node->error_depth++;
|
||||
node->error_count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -343,8 +343,8 @@ unsigned ts_stack_error_cost(const Stack *self, StackVersion version) {
|
|||
return array_get(&self->heads, version)->node->error_cost;
|
||||
}
|
||||
|
||||
unsigned ts_stack_error_depth(const Stack *self, StackVersion version) {
|
||||
return array_get(&self->heads, version)->node->error_depth;
|
||||
unsigned ts_stack_error_count(const Stack *self, StackVersion version) {
|
||||
return array_get(&self->heads, version)->node->error_count;
|
||||
}
|
||||
|
||||
bool ts_stack_push(Stack *self, StackVersion version, TSTree *tree,
|
||||
|
|
@ -473,7 +473,7 @@ bool ts_stack_merge(Stack *self, StackVersion version, StackVersion new_version)
|
|||
|
||||
if (new_node->state == node->state &&
|
||||
new_node->position.chars == node->position.chars &&
|
||||
new_node->error_depth == node->error_depth &&
|
||||
new_node->error_count == node->error_count &&
|
||||
new_node->error_cost == node->error_cost) {
|
||||
for (size_t j = 0; j < new_node->link_count; j++)
|
||||
stack_node_add_link(node, new_node->links[j]);
|
||||
|
|
@ -554,7 +554,7 @@ bool ts_stack_print_dot_graph(Stack *self, const char **symbol_names, FILE *f) {
|
|||
fprintf(
|
||||
f,
|
||||
" tooltip=\"position: %lu,%lu\nerror-count: %u\nerror-cost: %u\"];\n",
|
||||
node->position.rows, node->position.columns, node->error_depth,
|
||||
node->position.rows, node->position.columns, node->error_count,
|
||||
node->error_cost);
|
||||
|
||||
for (int j = 0; j < node->link_count; j++) {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ StackPopResult ts_stack_pop_pending(Stack *, StackVersion);
|
|||
|
||||
StackPopResult ts_stack_pop_all(Stack *, StackVersion);
|
||||
|
||||
unsigned ts_stack_error_depth(const Stack *, StackVersion);
|
||||
unsigned ts_stack_error_count(const Stack *, StackVersion);
|
||||
|
||||
unsigned ts_stack_error_cost(const Stack *, StackVersion);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue