Allow error recovery to look all the way to the bottom of the stack

Previously, there was a bug where the first node on the stack
would never be popped
This commit is contained in:
Max Brunsfeld 2015-11-11 16:56:58 -08:00
parent 1a5d5b3156
commit 40a90b551a
4 changed files with 3405 additions and 3956 deletions

View file

@ -1,3 +1,16 @@
==========================================
errors in top-level declarations
==========================================
int int int;
int y;
---
(translation_unit
(declaration (ERROR (identifier) (identifier) (UNEXPECTED 'i') (identifier)))
(declaration (identifier) (identifier)))
==========================================
errors in compound statements
==========================================

View file

@ -75,9 +75,10 @@ extern const Grammar c = Grammar({
sym("_declarator") }) },
{ "declaration", seq({
optional(sym("declaration_specifiers")),
sym("_type_specifier"),
comma_sep(sym("_init_declarator")),
err(seq({
optional(sym("declaration_specifiers")),
sym("_type_specifier"),
comma_sep1(sym("_init_declarator")) })),
str(";") }) },
{ "_init_declarator", choice({

File diff suppressed because it is too large Load diff

View file

@ -229,11 +229,11 @@ static bool ts_parser__handle_error(TSParser *self, int head) {
* expected and the current lookahead token is expected afterwards.
*/
int i = -1;
for (StackEntry *entry = entry_before_error; entry != NULL;
for (StackEntry *entry = entry_before_error; true;
entry = ts_stack_entry_next(entry, head), i++) {
TSStateId stack_state = entry->state;
TSParseAction action_on_error =
ts_language__action(self->language, stack_state, ts_builtin_sym_error);
TSStateId stack_state = entry ? entry->state : 0;
TSParseAction action_on_error = ts_language__action(
self->language, stack_state, ts_builtin_sym_error);
if (action_on_error.type == TSParseActionTypeShift) {
TSStateId state_after_error = action_on_error.data.to_state;
@ -247,6 +247,8 @@ static bool ts_parser__handle_error(TSParser *self, int head) {
return true;
}
}
if (!entry) break;
}
/*