Fix parse errors with tree-reuse

- Don't reuse error nodes
- When re-using nodes, update lexer's token_end_position
This commit is contained in:
Max Brunsfeld 2014-10-17 23:20:36 -07:00
parent ae0a7fc97d
commit 0962b21dd3
2 changed files with 25 additions and 2 deletions

View file

@ -103,7 +103,7 @@ static TSTree *break_down_right_stack(TSParser *parser) {
return NULL;
TSParseAction action = get_action(parser->language, state, node->symbol);
bool is_usable = (action.type != TSParseActionTypeError);
bool is_usable = (action.type != TSParseActionTypeError) && (node->symbol != ts_builtin_sym_error);
if (is_usable && right_subtree_start == current_position.chars) {
ts_stack_shrink(&parser->right_stack, parser->right_stack.size - 1);
return node;
@ -138,7 +138,8 @@ static TSTree *get_next_node(TSParser *parser, TSStateId lex_state) {
parser->lexer.lookahead = 0;
parser->lexer.lookahead_size = 0;
parser->lexer.current_position =
parser->lexer.token_start_position = ts_length_add(parser->lexer.current_position, node->padding);
parser->lexer.token_end_position = parser->lexer.current_position =
ts_length_add(parser->lexer.current_position, ts_tree_total_size(node));
} else {
node = parser->language->lex_fn(&parser->lexer, lex_state);