From 3d516aeeec3ff4251da19b2d3385a5aba86d7a1b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 3 Mar 2016 10:20:05 -0800 Subject: [PATCH] Give StackPushResult enumerators shorter names --- spec/runtime/stack_spec.cc | 20 ++++++++++---------- src/runtime/parser.c | 30 +++++++++++++++--------------- src/runtime/stack.c | 6 +++--- src/runtime/stack.h | 12 ++++++------ 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/spec/runtime/stack_spec.cc b/spec/runtime/stack_spec.cc index d2796484..e65c61da 100644 --- a/spec/runtime/stack_spec.cc +++ b/spec/runtime/stack_spec.cc @@ -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)); diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 57087141..591ad96a 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -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; diff --git a/src/runtime/stack.c b/src/runtime/stack.c index 15af2354..0aac66cf 100644 --- a/src/runtime/stack.c +++ b/src/runtime/stack.c @@ -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) { diff --git a/src/runtime/stack.h b/src/runtime/stack.h index 3d675775..ee0ec67a 100644 --- a/src/runtime/stack.h +++ b/src/runtime/stack.h @@ -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 *); /*