From 21a88b173191ad7e9a021283d2b73579cd17605c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 29 Dec 2017 16:10:43 -0800 Subject: [PATCH] Don't count less-far-along versions in better_version_exists method --- src/runtime/parser.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 65e267de..3fec5510 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -177,6 +177,7 @@ static bool parser__better_version_exists(Parser *self, StackVersion version, bool is_in_error, unsigned cost) { if (self->finished_tree && self->finished_tree->error_cost <= cost) return true; + Length position = ts_stack_top_position(self->stack, version); ErrorStatus status = { .cost = cost, .is_in_error = is_in_error, @@ -185,7 +186,9 @@ static bool parser__better_version_exists(Parser *self, StackVersion version, }; for (StackVersion i = 0, n = ts_stack_version_count(self->stack); i < n; i++) { - if (i == version || ts_stack_is_halted(self->stack, i)) continue; + if (i == version || + ts_stack_is_halted(self->stack, i) || + ts_stack_top_position(self->stack, i).bytes < position.bytes) continue; ErrorStatus status_i = { .cost = ts_stack_error_cost(self->stack, i), .is_in_error = ts_stack_top_state(self->stack, i) == ERROR_STATE,