From 31d1160e21bf3ff2f44d0e631500bcdbeb00ac7e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 29 Aug 2016 17:06:23 -0700 Subject: [PATCH] Base error costs on top-level trees skipped and lines of text skipped Rather than on the total number of tokens skipped --- .../error_corpus/javascript_errors.txt | 10 +++++----- src/runtime/stack.c | 2 +- src/runtime/tree.c | 20 ++++--------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/spec/fixtures/error_corpus/javascript_errors.txt b/spec/fixtures/error_corpus/javascript_errors.txt index ec8c80c4..03a80189 100644 --- a/spec/fixtures/error_corpus/javascript_errors.txt +++ b/spec/fixtures/error_corpus/javascript_errors.txt @@ -56,12 +56,12 @@ if ({a: 'b'} {c: 'd'}) { (program (if_statement - (object (pair (identifier) (string))) (ERROR (object (pair (identifier) (string)))) + (object (pair (identifier) (string))) (statement_block - (ERROR (function - (formal_parameters (identifier)) - (statement_block (expression_statement (identifier))))) (expression_statement (function (formal_parameters (identifier)) - (statement_block (expression_statement (identifier)))))))) + (statement_block (expression_statement (identifier)))) + (ERROR (function + (formal_parameters (identifier)) + (statement_block (expression_statement (identifier))))))))) diff --git a/src/runtime/stack.c b/src/runtime/stack.c index ac1e5998..d8fa4fd1 100644 --- a/src/runtime/stack.c +++ b/src/runtime/stack.c @@ -114,7 +114,7 @@ static StackNode *stack_node_new(StackNode *next, TSTree *tree, bool is_pending, ts_tree_retain(tree); if (state == TS_STATE_ERROR) { if (!tree->extra) { - node->error_cost++; + node->error_cost += 1 + tree->padding.rows + tree->size.rows; } } else { node->error_cost += tree->error_size; diff --git a/src/runtime/tree.c b/src/runtime/tree.c index 93ea81a5..456f824a 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -112,20 +112,6 @@ recur: } } -static void ts_tree_total_tokens(const TSTree *self, size_t *result) { -recur: - if (self->child_count == 0) { - if (!self->extra) { - (*result)++; - } - } else { - for (size_t i = 1; i < self->child_count; i++) - ts_tree_total_tokens(self->children[i], result); - self = self->children[0]; - goto recur; - } -} - void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) { if (self->child_count > 0) ts_free(self->children); @@ -164,8 +150,10 @@ void ts_tree_set_children(TSTree *self, size_t child_count, TSTree **children) { } if (self->symbol == ts_builtin_sym_error) { - self->error_size = 0; - ts_tree_total_tokens(self, &self->error_size); + self->error_size = self->size.rows; + for (size_t i = 0; i < child_count; i++) + if (!self->children[i]->extra) + self->error_size++; } if (child_count > 0) {