Try lexing using each parse stack head's state

This fixes the case where the parse stack is split and the top states
have different valid lookahead symbols
This commit is contained in:
Max Brunsfeld 2015-10-06 16:22:58 -07:00
parent 85466a5b22
commit 8ef25ffef3
2 changed files with 33 additions and 4 deletions

View file

@ -120,10 +120,21 @@ static void ts_parser__get_next_lookahead(TSParser *parser) {
return;
}
TSStateId parse_state = ts_stack_top_state(parser->stack, 0);
TSStateId lex_state = parser->language->lex_states[parse_state];
DEBUG("lex state:%d", lex_state);
parser->lookahead = parser->language->lex_fn(&parser->lexer, lex_state);
TSLength position = parser->lexer.current_position;
for (size_t i = 0, count = ts_stack_head_count(parser->stack); i < count; i++) {
if (i > 0) {
ts_lexer_reset(&parser->lexer, position);
ts_tree_release(parser->lookahead);
}
TSStateId parse_state = ts_stack_top_state(parser->stack, i);
TSStateId lex_state = parser->language->lex_states[parse_state];
DEBUG("lex state:%d", lex_state);
parser->lookahead = parser->language->lex_fn(&parser->lexer, lex_state);
if (parser->lookahead->symbol != ts_builtin_sym_error)
break;
}
}
/*