From 93d7a75b0930340be5f0b6cc39691b937b5ff301 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 7 Feb 2017 21:55:09 -0800 Subject: [PATCH] Suppress one unnecessary type of error recovery variation If we already have a stack version in which, for example, a `function_call` is skipped, don't create another stack version in which that `function_call` is reduced to an `expression`, and then the `expression` is skipped. That doesn't improve the error recovery at all, but adds to the branching factor of the parse stack and makes things harder to debug. --- spec/fixtures/error_corpus/c_errors.txt | 3 ++- src/runtime/parser.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/fixtures/error_corpus/c_errors.txt b/spec/fixtures/error_corpus/c_errors.txt index 05bc7ec2..4dfb0894 100644 --- a/spec/fixtures/error_corpus/c_errors.txt +++ b/spec/fixtures/error_corpus/c_errors.txt @@ -127,5 +127,6 @@ int b() { (ERROR (identifier) (identifier)) (identifier) (number_literal))) (declaration + (ERROR (identifier) (identifier)) (identifier) - (init_declarator (ERROR (identifier) (identifier)) (identifier) (number_literal)))))) + (init_declarator (identifier) (number_literal)))))) diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 3323f19d..d2ea8747 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -550,7 +550,7 @@ static StackPopResult parser__reduce(Parser *self, StackVersion version, // If this pop operation terminated at the end of an error region, then // create two stack versions: one in which the parent node is interpreted // normally, and one in which the parent node is skipped. - if (state == ERROR_STATE && allow_skipping) { + if (state == ERROR_STATE && allow_skipping && child_count > 1) { StackVersion other_version = ts_stack_copy_version(self->stack, slice.version); ts_stack_push(self->stack, other_version, parent, false, ERROR_STATE);