Fix stack breakdown procedure when there are trailing extra tokens

This commit is contained in:
Max Brunsfeld 2016-06-14 20:25:33 -07:00
parent e70547cd11
commit ecc7399ed3
2 changed files with 29 additions and 3 deletions

View file

@ -463,6 +463,29 @@ describe("Stack", [&]() {
free_slice_array(&pop.slices);
});
it("skips entries whose trees are extra", [&]() {
ts_stack_push(stack, 0, trees[1], true, stateB);
trees[2]->extra = true;
trees[3]->extra = true;
ts_stack_push(stack, 0, trees[2], false, stateB);
ts_stack_push(stack, 0, trees[3], false, stateB);
StackPopResult pop = ts_stack_pop_pending(stack, 0);
AssertThat(pop.status, Equals(StackPopResult::StackPopSucceeded));
AssertThat(pop.slices.size, Equals<size_t>(1));
AssertThat(pop.slices.contents[0].trees, Equals(vector<TSTree *>({ trees[1], trees[2], trees[3] })));
AssertThat(get_stack_entries(stack, 0), Equals(vector<StackEntry>({
{stateA, 0},
{0, 1},
})));
free_slice_array(&pop.slices);
});
it("does nothing if the top node was not pushed in pending mode", [&]() {
ts_stack_push(stack, 0, trees[1], false, stateB);

View file

@ -231,14 +231,17 @@ INLINE StackPopResult stack__iter(Stack *self, StackVersion version,
}
next_path->node = link.node;
if (!link.is_pending)
next_path->is_pending = false;
if (link.tree) {
if (!link.tree->extra)
if (!link.tree->extra) {
next_path->tree_count++;
if (!link.is_pending)
next_path->is_pending = false;
}
if (!array_push(&next_path->trees, link.tree))
goto error;
ts_tree_retain(link.tree);
} else {
next_path->is_pending = false;
}
}
}