This commit is contained in:
Max Brunsfeld 2014-05-08 13:27:48 -07:00
parent 34137be12d
commit 3f374c6547
2 changed files with 15 additions and 13 deletions

View file

@ -241,18 +241,17 @@ static const ts_parse_action * ts_lr_parser_table_actions(ts_lr_parser *parser,
}
static size_t ts_lr_parser_breakdown_stack(ts_lr_parser *parser, ts_input_edit *edit) {
ts_stack *stack = &parser->stack;
if (!edit) return 0;
ts_tree *node;
ts_stack *stack = &parser->stack;
size_t position = 0;
size_t child_count = 0;
for (;;) {
node = ts_stack_top_node(stack);
ts_tree *node = ts_stack_top_node(stack);
if (!node) break;
position = ts_stack_right_position(stack);
size_t child_count;
ts_tree **children = ts_tree_immediate_children(node, &child_count);
if (position <= edit->position && !children) break;
@ -307,7 +306,7 @@ static ts_symbol * ts_lr_parser_expected_symbols(ts_lr_parser *parser, size_t *c
size_t n = 0;
ts_symbol *result = malloc(*count * sizeof(*result));
for (size_t i = 0; i < parser->symbol_count; i++)
for (ts_symbol i = 0; i < parser->symbol_count; i++)
if (actions[i].type != ts_parse_action_type_error)
result[n++] = i;
@ -352,9 +351,10 @@ static int ts_lr_parser_handle_error(ts_lr_parser *parser) {
}
static const ts_tree * ts_parse(void *data, ts_input input, ts_input_edit *edit) {
int done = 0;
ts_lr_parser *parser = (ts_lr_parser *)data;
ts_lr_parser_initialize(parser, input, edit);
int done = 0;
while (!done) {
ts_state_id state = ts_stack_top_state(&parser->stack);
if (!parser->lookahead)
@ -380,6 +380,7 @@ static const ts_tree * ts_parse(void *data, ts_input input, ts_input_edit *edit)
break;
}
}
return ts_stack_root(&parser->stack);
}

View file

@ -71,20 +71,21 @@ ts_tree * ts_stack_reduce(ts_stack *stack,
static int collapse_flags[100];
int child_count = 0;
for (int i = 0; i < immediate_child_count; i++) {
ts_tree *child = stack->entries[stack->size - 1 - i].node;
size_t stack_index = stack->size - 1 - i;
ts_tree *child = stack->entries[stack_index].node;
size_t grandchild_count;
ts_tree **grandchildren = ts_tree_children(child, &grandchild_count);
ts_symbol symbol = ts_tree_symbol(child);
if (ubiquitous_symbol_flags[symbol])
immediate_child_count++;
ts_symbol child_symbol = ts_tree_symbol(child);
collapse_flags[i] = (
hidden_symbol_flags[symbol] ||
hidden_symbol_flags[child_symbol] ||
(grandchild_count == 1 && ts_tree_size(child) == ts_tree_size(grandchildren[0]))
);
child_count += (collapse_flags[i]) ? grandchild_count : 1;
child_count += collapse_flags[i] ? grandchild_count : 1;
if (ubiquitous_symbol_flags[child_symbol])
immediate_child_count++;
}
// Walk down the stack again, building up the array of children.