mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:36:22 -04:00
fix(parser): nest error children during recovery
This commit is contained in:
parent
869638f6cf
commit
f30ee2b300
|
|
@ -1250,10 +1250,17 @@ static bool ts_parser__recover_to_state(
|
|||
Subtree error_tree = *array_get(&error_trees, 0);
|
||||
uint32_t error_child_count = ts_subtree_child_count(error_tree);
|
||||
if (error_child_count > 0) {
|
||||
array_splice(&slice.subtrees, 0, 0, error_child_count, ts_subtree_children(error_tree));
|
||||
SubtreeArray nested = array_new();
|
||||
array_reserve(&nested, error_child_count);
|
||||
for (unsigned j = 0; j < error_child_count; j++) {
|
||||
ts_subtree_retain(*array_get(&slice.subtrees, j));
|
||||
Subtree child = ts_subtree_children(error_tree)[j];
|
||||
ts_subtree_retain(child);
|
||||
array_push(&nested, child);
|
||||
}
|
||||
Subtree nested_error = ts_subtree_from_mut(ts_subtree_new_node(
|
||||
ts_builtin_sym_error_repeat, &nested, 0, self->language
|
||||
));
|
||||
array_insert(&slice.subtrees, 0, nested_error);
|
||||
}
|
||||
ts_subtree_array_delete(&self->tree_pool, &error_trees);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue