Pass reference to parser in stack's tree selection callback

This commit is contained in:
Max Brunsfeld 2015-12-08 12:20:50 -08:00
parent 4abb415113
commit 10286f307f
4 changed files with 21 additions and 8 deletions

View file

@ -36,13 +36,17 @@ typedef struct {
* Section: Stack lifecycle
*/
Stack *ts_stack_new(TreeSelectionCallback tree_selection_callback) {
static TSTree *ts_stack__default_tree_selection(void *p, TSTree *t1, TSTree *t2) {
return t1;
}
Stack *ts_stack_new() {
Stack *self = malloc(sizeof(Stack));
*self = (Stack){
.heads = calloc(INITIAL_HEAD_CAPACITY, sizeof(StackNode *)),
.head_count = 1,
.head_capacity = INITIAL_HEAD_CAPACITY,
.tree_selection_callback = tree_selection_callback,
.tree_selection_callback = {NULL, ts_stack__default_tree_selection},
.pop_results = vector_new(sizeof(StackPopResult), 4),
.pop_paths = vector_new(sizeof(PopPath), 4),
};
@ -351,3 +355,7 @@ void ts_stack_clear(Stack *self) {
self->head_count = 1;
self->heads[0] = NULL;
}
void ts_stack_set_tree_selection_callback(Stack *self, TreeSelectionCallback callback) {
self->tree_selection_callback = callback;
}