Avoid reusing the root node during incremental parsing

Fixes #712
This commit is contained in:
Max Brunsfeld 2020-09-23 12:59:24 -07:00
parent 4d99e23946
commit cb343cad5e
2 changed files with 28 additions and 9 deletions

View file

@ -20,15 +20,6 @@ static inline void reusable_node_clear(ReusableNode *self) {
self->last_external_token = NULL_SUBTREE;
}
static inline void reusable_node_reset(ReusableNode *self, Subtree tree) {
reusable_node_clear(self);
array_push(&self->stack, ((StackEntry) {
.tree = tree,
.child_index = 0,
.byte_offset = 0,
}));
}
static inline Subtree reusable_node_tree(ReusableNode *self) {
return self->stack.size > 0
? self->stack.contents[self->stack.size - 1].tree
@ -86,3 +77,19 @@ static inline void reusable_node_advance_past_leaf(ReusableNode *self) {
while (reusable_node_descend(self)) {}
reusable_node_advance(self);
}
static inline void reusable_node_reset(ReusableNode *self, Subtree tree) {
reusable_node_clear(self);
array_push(&self->stack, ((StackEntry) {
.tree = tree,
.child_index = 0,
.byte_offset = 0,
}));
// Never reuse the root node, because it has a non-standard internal structure
// due to transformations that are applied when it is accepted: adding the EOF
// child and any extra children.
if (!reusable_node_descend(self)) {
reusable_node_clear(self);
}
}