Fix off-by-one error in storing reusable right-subtree

This commit is contained in:
Max Brunsfeld 2014-10-10 12:10:23 -07:00
parent 3bcb221379
commit f460b921e2
2 changed files with 12 additions and 9 deletions

View file

@ -107,7 +107,7 @@ static TSLength breakdown_stack(TSParser *parser, TSInputEdit *edit) {
position = ts_length_add(position, ts_tree_total_size(child));
}
for (size_t j = child_count - 1; j + 1 > i + 1; j--) {
for (size_t j = child_count - 1; j + 1 > i; j--) {
TSTree *child = children[j];
DEBUG_PARSE("PUSH RIGHT %s",
parser->language->symbol_names[child->symbol]);
@ -127,14 +127,18 @@ static void lex(TSParser *parser, TSStateId lex_state) {
breakdown_right_stack(parser, parser->lexer.current_position, state);
TSTree *node = ts_stack_top_node(&parser->right_stack);
if (node && node_position == parser->lexer.current_position.chars) {
DEBUG_PARSE("REUSE %s", parser->language->symbol_names[node->symbol]);
ts_stack_shrink(&parser->right_stack, parser->right_stack.size - 1);
parser->lexer.lookahead = 0;
parser->lexer.lookahead_size = 0;
parser->lookahead = node;
parser->lexer.current_position =
ts_length_add(parser->lexer.current_position, ts_tree_total_size(node));
DEBUG_PARSE("REUSE %s", parser->language->symbol_names[node->symbol]);
} else {
parser->lookahead = parser->language->lex_fn(&parser->lexer, lex_state);
DEBUG_PARSE("TOKEN %s",
parser->language->symbol_names[parser->lookahead->symbol]);
}
}
@ -298,9 +302,6 @@ const TSTree *ts_parser_parse(TSParser *parser, TSInput input,
TSParseAction action =
action_for(parser->language, state, parser->lookahead->symbol);
DEBUG_PARSE("LOOKAHEAD %s",
parser->language->symbol_names[parser->lookahead->symbol]);
switch (action.type) {
case TSParseActionTypeShift:
if (parser->lookahead->symbol == ts_builtin_sym_error) {