Get tests passing w/ new alias API
This commit is contained in:
parent
cb5fe80348
commit
09f4796f6b
18 changed files with 99 additions and 94 deletions
|
|
@ -33,10 +33,10 @@ static inline uint32_t ts_node__offset_row(TSNode self) {
|
|||
|
||||
static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) {
|
||||
const Tree *tree = ts_node__tree(self);
|
||||
if (tree->context.alias_symbol > 0) {
|
||||
return true;
|
||||
if (include_anonymous) {
|
||||
return tree->context.alias_symbol || tree->visible;
|
||||
} else {
|
||||
return include_anonymous ? tree->visible : tree->visible && tree->named;
|
||||
return tree->context.alias_is_named || (tree->visible && tree->named);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -541,17 +541,11 @@ static void parser__shift(Parser *self, StackVersion version, TSStateId state,
|
|||
}
|
||||
|
||||
static bool parser__replace_children(Parser *self, Tree *tree, Tree **children, uint32_t count) {
|
||||
self->scratch_tree.symbol = tree->symbol;
|
||||
self->scratch_tree = *tree;
|
||||
self->scratch_tree.child_count = 0;
|
||||
ts_tree_set_children(&self->scratch_tree, count, children, self->language);
|
||||
if (parser__select_tree(self, tree, &self->scratch_tree)) {
|
||||
tree->size = self->scratch_tree.size;
|
||||
tree->padding = self->scratch_tree.padding;
|
||||
tree->error_cost = self->scratch_tree.error_cost;
|
||||
tree->children = self->scratch_tree.children;
|
||||
tree->child_count = self->scratch_tree.child_count;
|
||||
tree->named_child_count = self->scratch_tree.named_child_count;
|
||||
tree->visible_child_count = self->scratch_tree.visible_child_count;
|
||||
*tree = self->scratch_tree;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -790,15 +784,17 @@ static bool parser__repair_error(Parser *self, StackSlice slice,
|
|||
|
||||
array_clear(&self->reduce_actions);
|
||||
for (uint32_t i = 0; i < entry.action_count; i++) {
|
||||
if (entry.actions[i].type == TSParseActionTypeReduce) {
|
||||
TSSymbol symbol = entry.actions[i].params.symbol;
|
||||
uint32_t child_count = entry.actions[i].params.child_count;
|
||||
TSParseAction action = entry.actions[i];
|
||||
if (action.type == TSParseActionTypeReduce) {
|
||||
TSSymbol symbol = action.params.symbol;
|
||||
uint32_t child_count = action.params.child_count;
|
||||
if ((child_count > session.tree_count_above_error) ||
|
||||
(child_count == session.tree_count_above_error &&
|
||||
!ts_language_symbol_metadata(self->language, symbol).visible))
|
||||
array_push(&self->reduce_actions, ((ReduceAction){
|
||||
.symbol = symbol,
|
||||
.count = child_count
|
||||
.count = child_count,
|
||||
.alias_sequence_id = action.params.alias_sequence_id,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
@ -816,7 +812,6 @@ static bool parser__repair_error(Parser *self, StackSlice slice,
|
|||
ReduceAction repair = session.best_repair;
|
||||
TSStateId next_state = session.best_repair_next_state;
|
||||
uint32_t skip_count = session.best_repair_skip_count;
|
||||
TSSymbol symbol = repair.symbol;
|
||||
|
||||
StackSlice new_slice = array_pop(&pop.slices);
|
||||
TreeArray children = new_slice.trees;
|
||||
|
|
@ -832,6 +827,7 @@ static bool parser__repair_error(Parser *self, StackSlice slice,
|
|||
TreeArray skipped_children = ts_tree_array_remove_last_n(&children, skip_count);
|
||||
TreeArray trailing_extras = ts_tree_array_remove_trailing_extras(&skipped_children);
|
||||
Tree *error = ts_tree_make_error_node(&skipped_children, self->language);
|
||||
error->extra = true;
|
||||
array_push(&children, error);
|
||||
array_push_all(&children, &trailing_extras);
|
||||
trailing_extras.size = 0;
|
||||
|
|
@ -842,8 +838,8 @@ static bool parser__repair_error(Parser *self, StackSlice slice,
|
|||
array_delete(&slice.trees);
|
||||
|
||||
Tree *parent = ts_tree_make_node(
|
||||
symbol, children.size, children.contents,
|
||||
0, self->language
|
||||
repair.symbol, children.size, children.contents,
|
||||
repair.alias_sequence_id, self->language
|
||||
);
|
||||
parser__push(self, slice.version, parent, next_state);
|
||||
ts_stack_decrease_push_count(self->stack, slice.version, error->child_count);
|
||||
|
|
@ -854,7 +850,7 @@ static bool parser__repair_error(Parser *self, StackSlice slice,
|
|||
ts_stack_halt(self->stack, slice.version);
|
||||
return false;
|
||||
} else {
|
||||
LOG("repair_found sym:%s, child_count:%u, cost:%u", SYM_NAME(symbol),
|
||||
LOG("repair_found sym:%s, child_count:%u, cost:%u", SYM_NAME(repair.symbol),
|
||||
repair.count, parent->error_cost);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,15 +50,18 @@ Tree *ts_tree_make_leaf(TSSymbol symbol, Length padding, Length size, const TSLa
|
|||
.symbol = symbol,
|
||||
.size = size,
|
||||
.child_count = 0,
|
||||
.children = NULL,
|
||||
.visible_child_count = 0,
|
||||
.named_child_count = 0,
|
||||
.children = NULL,
|
||||
.alias_sequence_id = 0,
|
||||
.padding = padding,
|
||||
.visible = metadata.visible,
|
||||
.named = metadata.named,
|
||||
.has_changes = false,
|
||||
.first_leaf.symbol = symbol,
|
||||
.first_leaf = {
|
||||
.symbol = symbol,
|
||||
.lex_mode = {0, 0},
|
||||
},
|
||||
.has_external_tokens = false,
|
||||
};
|
||||
return result;
|
||||
|
|
@ -170,6 +173,7 @@ void ts_tree_assign_parents(Tree *self, TreePath *path, const TSLanguage *langua
|
|||
child->context.alias_is_named = metadata.named;
|
||||
} else {
|
||||
child->context.alias_symbol = 0;
|
||||
child->context.alias_is_named = false;
|
||||
}
|
||||
array_push(path, ((TreePathEntry){child, length_zero(), 0}));
|
||||
}
|
||||
|
|
@ -514,9 +518,8 @@ 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 Tree *self,
|
||||
const TSLanguage *language, char *string,
|
||||
size_t limit, bool is_root,
|
||||
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) {
|
||||
if (!self) return snprintf(string, limit, "(NULL)");
|
||||
|
||||
|
|
|
|||
|
|
@ -137,19 +137,18 @@ TreePathComparison tree_path_compare(const TreePath *old_path,
|
|||
Length old_start = length_zero();
|
||||
for (uint32_t i = old_path->size - 1; i + 1 > 0; i--) {
|
||||
old_tree = old_path->contents[i].tree;
|
||||
if (old_tree->visible) {
|
||||
old_start = old_path->contents[i].position;
|
||||
if (i > 0) {
|
||||
const TSSymbol *alias_sequence = ts_language_alias_sequence(
|
||||
language,
|
||||
old_path->contents[i - 1].tree->alias_sequence_id
|
||||
);
|
||||
if (alias_sequence) {
|
||||
old_alias_symbol = alias_sequence[old_path->contents[i].child_index];
|
||||
}
|
||||
old_start = old_path->contents[i].position;
|
||||
if (i > 0) {
|
||||
const TSSymbol *alias_sequence = ts_language_alias_sequence(
|
||||
language,
|
||||
old_path->contents[i - 1].tree->alias_sequence_id
|
||||
);
|
||||
if (alias_sequence) {
|
||||
old_alias_symbol = alias_sequence[old_path->contents[i].child_index];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (old_tree->visible || old_alias_symbol) break;
|
||||
}
|
||||
|
||||
Tree *new_tree = NULL;
|
||||
|
|
@ -157,19 +156,18 @@ TreePathComparison tree_path_compare(const TreePath *old_path,
|
|||
Length new_start = length_zero();
|
||||
for (uint32_t i = new_path->size - 1; i + 1 > 0; i--) {
|
||||
new_tree = new_path->contents[i].tree;
|
||||
if (new_tree->visible) {
|
||||
new_start = old_path->contents[i].position;
|
||||
if (i > 0) {
|
||||
const TSSymbol *alias_sequence = ts_language_alias_sequence(
|
||||
language,
|
||||
new_path->contents[i - 1].tree->alias_sequence_id
|
||||
);
|
||||
if (alias_sequence) {
|
||||
new_alias_symbol = alias_sequence[new_path->contents[i].child_index];
|
||||
}
|
||||
new_start = old_path->contents[i].position;
|
||||
if (i > 0) {
|
||||
const TSSymbol *alias_sequence = ts_language_alias_sequence(
|
||||
language,
|
||||
new_path->contents[i - 1].tree->alias_sequence_id
|
||||
);
|
||||
if (alias_sequence) {
|
||||
new_alias_symbol = alias_sequence[new_path->contents[i].child_index];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (new_tree->visible || new_alias_symbol) break;
|
||||
}
|
||||
|
||||
if (old_alias_symbol == new_alias_symbol) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue