Refactor construction of out-of-context states
This commit is contained in:
parent
e99a3925e0
commit
31f6b2e24a
7 changed files with 51 additions and 41 deletions
|
|
@ -264,11 +264,13 @@ static bool ts_parser__select_tree(TSParser *self, TSTree *left, TSTree *right)
|
|||
if (!right)
|
||||
return false;
|
||||
if (right->error_size < left->error_size) {
|
||||
LOG_ACTION("select_smaller_error symbol:%s, over_symbol:%s", SYM_NAME(right->symbol), SYM_NAME(left->symbol));
|
||||
LOG_ACTION("select_smaller_error symbol:%s, over_symbol:%s",
|
||||
SYM_NAME(right->symbol), SYM_NAME(left->symbol));
|
||||
return true;
|
||||
}
|
||||
if (left->error_size < right->error_size) {
|
||||
LOG_ACTION("select_smaller_error symbol:%s, over_symbol:%s", SYM_NAME(left->symbol), SYM_NAME(right->symbol));
|
||||
LOG_ACTION("select_smaller_error symbol:%s, over_symbol:%s",
|
||||
SYM_NAME(left->symbol), SYM_NAME(right->symbol));
|
||||
return false;
|
||||
}
|
||||
return ts_tree_compare(right, left) < 0;
|
||||
|
|
@ -314,7 +316,7 @@ error:
|
|||
}
|
||||
|
||||
static bool ts_parser__switch_children(TSParser *self, TSTree *tree,
|
||||
TSTree **children, size_t count) {
|
||||
TSTree **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);
|
||||
|
|
@ -534,8 +536,8 @@ static RepairResult ts_parser__repair_error(TSParser *self, StackSlice slice,
|
|||
|
||||
LOG_ACTION(
|
||||
"repair_found sym:%s, child_count:%lu, match_count:%lu, skipped:%lu",
|
||||
SYM_NAME(symbol), repair.count_below_error + count_above_error, repair.in_progress_state_count,
|
||||
skip_count);
|
||||
SYM_NAME(symbol), repair.count_below_error + count_above_error,
|
||||
repair.in_progress_state_count, skip_count);
|
||||
|
||||
if (skip_count > 0) {
|
||||
TreeArray skipped_children = array_new();
|
||||
|
|
|
|||
|
|
@ -134,9 +134,9 @@ static StackVersion ts_stack__add_version(Stack *self, StackNode *node) {
|
|||
|
||||
static bool ts_stack__add_slice(Stack *self, StackNode *node, TreeArray *trees) {
|
||||
for (size_t i = self->slices.size - 1; i + 1 > 0; i--) {
|
||||
StackVersion version = self->slices.contents[i].version;
|
||||
StackVersion version = self->slices.contents[i].version;
|
||||
if (self->heads.contents[version] == node) {
|
||||
StackSlice slice = {*trees, version};
|
||||
StackSlice slice = { *trees, version };
|
||||
return array_insert(&self->slices, i + 1, slice);
|
||||
}
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ static bool ts_stack__add_slice(Stack *self, StackNode *node, TreeArray *trees)
|
|||
StackVersion version = ts_stack__add_version(self, node);
|
||||
if (version == STACK_VERSION_NONE)
|
||||
return false;
|
||||
StackSlice slice = {*trees, version};
|
||||
StackSlice slice = { *trees, version };
|
||||
return array_push(&self->slices, slice);
|
||||
}
|
||||
|
||||
|
|
@ -442,7 +442,10 @@ int ts_stack_print_dot_graph(Stack *self, const char **symbol_names, FILE *f) {
|
|||
for (size_t i = 0; i < self->heads.size; i++) {
|
||||
StackNode *node = self->heads.contents[i];
|
||||
fprintf(f, "node_head_%lu [shape=none, label=\"\"]\n", i);
|
||||
fprintf(f, "node_head_%lu -> node_%p [label=%lu, arrowhead=none, fontcolor=blue, weight=10000]\n", i, node, i);
|
||||
fprintf(f,
|
||||
"node_head_%lu -> node_%p [label=%lu, arrowhead=none, "
|
||||
"fontcolor=blue, weight=10000]\n",
|
||||
i, node, i);
|
||||
array_push(&self->pop_paths, ((PopPath){.node = node }));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue