From d6579956f5810cf0fe24e217588c6be04b6570ff Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 30 Jun 2017 17:45:05 -0700 Subject: [PATCH] Enforce a hard version count limit during the recovery action --- src/runtime/parser.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/runtime/parser.c b/src/runtime/parser.c index b77ec2b3..cfb1528b 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -40,7 +40,8 @@ #define SYM_NAME(symbol) ts_language_symbol_name(self->language, symbol) -static const uint32_t MAX_STACK_VERSION_COUNT = 16; +static const uint32_t SOFT_MAX_VERSION_COUNT = 10; +static const uint32_t HARD_MAX_VERSION_COUNT = 18; typedef struct { Parser *parser; @@ -214,8 +215,8 @@ static CondenseResult parser__condense_stack(Parser *self) { } } - while (ts_stack_version_count(self->stack) > MAX_STACK_VERSION_COUNT) { - ts_stack_remove_version(self->stack, MAX_STACK_VERSION_COUNT); + while (ts_stack_version_count(self->stack) > SOFT_MAX_VERSION_COUNT) { + ts_stack_remove_version(self->stack, SOFT_MAX_VERSION_COUNT); result |= CondenseResultMadeChange; } @@ -1085,9 +1086,13 @@ static void parser__recover(Parser *self, StackVersion version, TSStateId state, } LOG("recover state:%u", state); - StackVersion new_version = ts_stack_copy_version(self->stack, version); - bool can_be_extra = ts_language_symbol_metadata(self->language, lookahead->symbol).extra; - parser__shift(self, new_version, ERROR_STATE, lookahead, can_be_extra); + + if (ts_stack_version_count(self->stack) < HARD_MAX_VERSION_COUNT) { + StackVersion new_version = ts_stack_copy_version(self->stack, version); + bool can_be_extra = ts_language_symbol_metadata(self->language, lookahead->symbol).extra; + parser__shift(self, new_version, ERROR_STATE, lookahead, can_be_extra); + } + parser__shift(self, version, state, lookahead, false); }