Avoid including trailing extra tokens within error nodes unnecessarily

This commit is contained in:
Max Brunsfeld 2017-02-19 13:53:28 -08:00
parent 135d8ef4e0
commit c14a776a3d
5 changed files with 42 additions and 0 deletions

View file

@ -84,6 +84,21 @@ TreeArray ts_tree_array_remove_last_n(TreeArray *self, uint32_t remove_count) {
return result;
}
TreeArray ts_tree_array_remove_trailing_extras(TreeArray *self) {
TreeArray result = array_new();
uint32_t i = self->size - 1;
for (; i + 1 > 0; i--) {
Tree *child = self->contents[i];
if (!child->extra) break;
array_push(&result, child);
}
self->size = i + 1;
array_reverse(&result);
return result;
}
Tree *ts_tree_make_error(Length size, Length padding, char lookahead_char) {
Tree *result = ts_tree_make_leaf(ts_builtin_sym_error, padding, size,
(TSSymbolMetadata){