Split parse stack when there are multiple parse actions
This commit is contained in:
parent
f26ddf5187
commit
aff8bc3266
12 changed files with 1563 additions and 907 deletions
|
|
@ -185,7 +185,7 @@ describe("ParseStack", [&]() {
|
|||
});
|
||||
|
||||
describe("when the trees are identical", [&]() {
|
||||
it("merges the heads, and removes nodes along both heads on subsequent pop operations", [&]() {
|
||||
before_each([&]() {
|
||||
/*
|
||||
* A0__B1__C2__D3__G6.
|
||||
* \__E4__F5__/
|
||||
|
|
@ -194,14 +194,18 @@ describe("ParseStack", [&]() {
|
|||
AssertThat(merged, IsFalse());
|
||||
merged = ts_parse_stack_push(stack, 1, stateG, trees[6]);
|
||||
AssertThat(merged, IsTrue());
|
||||
});
|
||||
|
||||
it("merges the heads", [&]() {
|
||||
AssertThat(ts_parse_stack_head_count(stack), Equals(1));
|
||||
const ParseStackEntry *entry1 = ts_parse_stack_head(stack, 0);
|
||||
AssertThat(*entry1, Equals<ParseStackEntry>({trees[6], stateG}));
|
||||
AssertThat(ts_parse_stack_entry_next_count(entry1), Equals(2));
|
||||
AssertThat(*ts_parse_stack_entry_next(entry1, 0), Equals<ParseStackEntry>({trees[3], stateD}));
|
||||
AssertThat(*ts_parse_stack_entry_next(entry1, 1), Equals<ParseStackEntry>({trees[5], stateF}));
|
||||
});
|
||||
|
||||
it("removes nodes along both heads on subsequent pop operations", [&]() {
|
||||
/*
|
||||
* A0__B1__C2.
|
||||
* \__E4.
|
||||
|
|
@ -220,6 +224,56 @@ describe("ParseStack", [&]() {
|
|||
AssertThat(*ts_parse_stack_head(stack, 0), Equals<ParseStackEntry>({trees[2], stateC}));
|
||||
AssertThat(*ts_parse_stack_head(stack, 1), Equals<ParseStackEntry>({trees[4], stateE}));
|
||||
});
|
||||
|
||||
it("pops only one path if the split is hidden under sufficiently many nodes", [&]() {
|
||||
/*
|
||||
* A0__B1__C2__D3__G6__H7.
|
||||
* \__E4__F5__/
|
||||
*/
|
||||
merged = ts_parse_stack_push(stack, 0, stateH, trees[7]);
|
||||
AssertThat(merged, IsFalse());
|
||||
AssertThat(ts_parse_stack_head_count(stack), Equals(1));
|
||||
|
||||
/*
|
||||
* A0__B1__C2__D3__G6.
|
||||
* \__E4__F5__/
|
||||
*/
|
||||
ParseStackPopResultList pop = ts_parse_stack_pop(stack, 0, 1, false);
|
||||
|
||||
AssertThat(pop.size, Equals(1));
|
||||
AssertThat(ts_parse_stack_head_count(stack), Equals(1));
|
||||
});
|
||||
|
||||
it("can pop one branch that reveals two head", [&]() {
|
||||
/*
|
||||
* A0__B1__C2__D3.
|
||||
* \__E4__F5.
|
||||
*/
|
||||
ParseStackPopResultList pop = ts_parse_stack_pop(stack, 0, 1, false);
|
||||
AssertThat(ts_parse_stack_head_count(stack), Equals(2));
|
||||
|
||||
AssertThat(pop.size, Equals(2));
|
||||
AssertThat(pop.contents[0].index, Equals(0));
|
||||
AssertThat(pop.contents[1].index, Equals(1));
|
||||
AssertThat(pop.contents[0].trees, Equals(pop.contents[1].trees));
|
||||
});
|
||||
|
||||
it("can pop two branches that converge at the same head", [&]() {
|
||||
/*
|
||||
* A0__B1.
|
||||
*/
|
||||
ParseStackPopResultList pop = ts_parse_stack_pop(stack, 0, 3, false);
|
||||
AssertThat(ts_parse_stack_head_count(stack), Equals(1));
|
||||
AssertThat(*ts_parse_stack_head(stack, 0), Equals<ParseStackEntry>({trees[1], stateB}));
|
||||
|
||||
AssertThat(pop.size, Equals(2));
|
||||
AssertThat(pop.contents[0].tree_count, Equals(3));
|
||||
AssertThat(pop.contents[0].index, Equals(0));
|
||||
AssertThat(pop.contents[0].trees[0], Equals(trees[2]));
|
||||
AssertThat(pop.contents[1].tree_count, Equals(3));
|
||||
AssertThat(pop.contents[1].index, Equals(0));
|
||||
AssertThat(pop.contents[1].trees[0], Equals(trees[4]));
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the trees are different", [&]() {
|
||||
|
|
@ -235,7 +289,7 @@ describe("ParseStack", [&]() {
|
|||
|
||||
AssertThat(ts_parse_stack_head_count(stack), Equals(1));
|
||||
AssertThat(*ts_parse_stack_head(stack, 0), Equals<ParseStackEntry>({
|
||||
ts_tree_make_ambiguity(2, tree_array({ trees[6], trees[7] })),
|
||||
ts_tree_make_ambiguity(trees[6], trees[7]),
|
||||
stateG
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue