Give StackPushResult enumerators shorter names

This commit is contained in:
Max Brunsfeld 2016-03-03 10:20:05 -08:00
parent 8a13b5d120
commit 3d516aeeec
4 changed files with 34 additions and 34 deletions

View file

@ -253,8 +253,8 @@ describe("Stack", [&]() {
// . <──0── A <──1── B <──2── C <──3── D <──6── G*
// ↑ |
// └───4─── E <──5── F <──7───┘
AssertThat(ts_stack_push(stack, 0, trees[6], stateG), Equals(StackPushResultContinued));
AssertThat(ts_stack_push(stack, 1, trees[7], stateG), Equals(StackPushResultMerged));
AssertThat(ts_stack_push(stack, 0, trees[6], stateG), Equals(StackPushContinued));
AssertThat(ts_stack_push(stack, 1, trees[7], stateG), Equals(StackPushMerged));
AssertThat(ts_stack_head_count(stack), Equals(1));
const StackEntry *entry1 = ts_stack_head(stack, 0);
@ -269,14 +269,14 @@ describe("Stack", [&]() {
// . <──0── A <──1── B <──2── C <──3── D <──6── G <──7──H*
// ↑
// └───4─── E <──5── F <──8── G*
AssertThat(ts_stack_push(stack, 0, trees[6], stateG), Equals(StackPushResultContinued));
AssertThat(ts_stack_push(stack, 0, trees[7], stateH), Equals(StackPushResultContinued));
AssertThat(ts_stack_push(stack, 1, trees[6], stateG), Equals(StackPushResultContinued));
AssertThat(ts_stack_push(stack, 0, trees[6], stateG), Equals(StackPushContinued));
AssertThat(ts_stack_push(stack, 0, trees[7], stateH), Equals(StackPushContinued));
AssertThat(ts_stack_push(stack, 1, trees[6], stateG), Equals(StackPushContinued));
// . <──0── A <──1── B <──2── C <──3── D <──6── G <──7──H*
// ↑ |
// └───4─── E <──5── F <──8───┘
AssertThat(ts_stack_push(stack, 1, trees[7], stateH), Equals(StackPushResultMerged));
AssertThat(ts_stack_push(stack, 1, trees[7], stateH), Equals(StackPushMerged));
AssertThat(ts_stack_head_count(stack), Equals(1));
StackEntry *head = ts_stack_head(stack, 0);
@ -300,9 +300,9 @@ describe("Stack", [&]() {
// └────────5────────┘
ts_stack_clear(stack);
ts_stack_split(stack, 0);
AssertThat(ts_stack_push(stack, 0, parent, stateC), Equals(StackPushResultContinued));
AssertThat(ts_stack_push(stack, 1, trees[2], stateB), Equals(StackPushResultContinued));
AssertThat(ts_stack_push(stack, 1, trees[3], stateC), Equals(StackPushResultMerged));
AssertThat(ts_stack_push(stack, 0, parent, stateC), Equals(StackPushContinued));
AssertThat(ts_stack_push(stack, 1, trees[2], stateB), Equals(StackPushContinued));
AssertThat(ts_stack_push(stack, 1, trees[3], stateC), Equals(StackPushMerged));
AssertThat(ts_stack_head_count(stack), Equals(1));
StackEntry *head = ts_stack_head(stack, 0);
@ -368,7 +368,7 @@ describe("Stack", [&]() {
// . <──0── A <──1── B <──2── C <──3── D <──4── E <──8──H*
// ↑ |
// └───5─── F <──6── G <──7───┘
AssertThat(ts_stack_push(stack, 0, trees[8], stateH), Equals(StackPushResultContinued));
AssertThat(ts_stack_push(stack, 0, trees[8], stateH), Equals(StackPushContinued));
AssertThat(ts_stack_head_count(stack), Equals(1));
AssertThat(ts_stack_top_state(stack, 0), Equals(stateH));

View file

@ -102,7 +102,7 @@ static ParseActionResult ts_parser__breakdown_top_of_stack(TSParser *self,
LOG("breakdown_pop sym:%s, size:%lu", SYM_NAME(parent->symbol),
ts_tree_total_size(parent).chars);
StackPushResult last_push = StackPushResultContinued;
StackPushResult last_push = StackPushContinued;
TSStateId state = ts_stack_top_state(self->stack, head_index);
for (size_t j = 0; j < parent->child_count; j++) {
last_child = parent->children[j];
@ -117,21 +117,21 @@ static ParseActionResult ts_parser__breakdown_top_of_stack(TSParser *self,
ts_tree_total_size(last_child).chars);
last_push = ts_stack_push(self->stack, head_index, last_child, state);
if (last_push == StackPushResultFailed)
if (last_push == StackPushFailed)
goto error;
}
for (size_t j = 1, count = slice.trees.size; j < count; j++) {
TSTree *tree = slice.trees.contents[j];
last_push = ts_stack_push(self->stack, head_index, tree, state);
if (last_push == StackPushResultFailed)
if (last_push == StackPushFailed)
goto error;
}
if (i == 0)
assert(last_push != StackPushResultMerged);
assert(last_push != StackPushMerged);
else
assert(last_push == StackPushResultMerged);
assert(last_push == StackPushMerged);
for (size_t j = 0, count = removed_trees.size; j < count; j++)
ts_tree_release(removed_trees.contents[j]);
@ -309,9 +309,9 @@ static ParseActionResult ts_parser__shift(TSParser *self, int head,
TSStateId parse_state,
TSTree *lookahead) {
switch (ts_stack_push(self->stack, head, lookahead, parse_state)) {
case StackPushResultFailed:
case StackPushFailed:
return FailedToUpdateStackHead;
case StackPushResultMerged:
case StackPushMerged:
LOG("merge head:%d", head);
array_erase(&self->lookahead_states, head);
return RemovedStackHead;
@ -449,15 +449,15 @@ static ReduceResult ts_parser__reduce(TSParser *self, int head, TSSymbol symbol,
* then remove the lookahead state for the head.
*/
switch (ts_stack_push(self->stack, new_head, parent, state)) {
case StackPushResultFailed:
case StackPushFailed:
ts_tree_release(parent);
goto error;
case StackPushResultMerged:
case StackPushMerged:
LOG("merge_during_reduce head:%d", new_head);
array_erase(&self->lookahead_states, new_head);
removed_heads++;
continue;
case StackPushResultContinued:
case StackPushContinued:
break;
}
@ -466,13 +466,13 @@ static ReduceResult ts_parser__reduce(TSParser *self, int head, TSSymbol symbol,
size_t index = slice.trees.size - trailing_extra_count + j;
TSTree *tree = slice.trees.contents[index];
switch (ts_stack_push(self->stack, new_head, tree, state)) {
case StackPushResultFailed:
case StackPushFailed:
return ReduceFailed;
case StackPushResultMerged:
case StackPushMerged:
array_erase(&self->lookahead_states, new_head);
removed_heads++;
break;
case StackPushResultContinued:
case StackPushContinued:
break;
}
ts_tree_release(tree);
@ -666,9 +666,9 @@ static ParseActionResult ts_parser__repair_error(TSParser *self, int head_index,
StackPushResult push_result = ts_stack_push(self->stack, head_index, parent, best_repair.next_state);
ts_tree_release(parent);
switch (push_result) {
case StackPushResultFailed:
case StackPushFailed:
return FailedToUpdateStackHead;
case StackPushResultMerged:
case StackPushMerged:
return RemovedStackHead;
default:
return UpdatedStackHead;

View file

@ -285,18 +285,18 @@ StackPushResult ts_stack_push(Stack *self, int head_index, TSTree *tree,
ts_length_eq(prior_entry.position, position)) {
stack_node__add_successor(prior_node, tree, current_head);
ts_stack_remove_head(self, head_index);
return StackPushResultMerged;
return StackPushMerged;
}
}
StackNode *new_head =
stack_node_new(current_head, tree, state, &self->node_pool);
if (!new_head)
return StackPushResultFailed;
return StackPushFailed;
stack_node_release(current_head, &self->node_pool);
self->heads.contents[head_index] = new_head;
return StackPushResultContinued;
return StackPushContinued;
}
int ts_stack_split(Stack *self, int head_index) {

View file

@ -21,14 +21,14 @@ typedef struct {
int head_index;
} StackSlice;
typedef enum {
StackPushResultFailed,
StackPushResultMerged,
StackPushResultContinued,
} StackPushResult;
typedef Array(StackSlice) StackSliceArray;
typedef enum {
StackPushFailed,
StackPushMerged,
StackPushContinued,
} StackPushResult;
typedef int (*TreeSelectionFunction)(void *, TSTree *, TSTree *);
/*