diff --git a/src/runtime/parser.c b/src/runtime/parser.c index e6c2c1dd..f4f01a03 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -194,7 +194,10 @@ static CondenseResult parser__condense_stack(Parser *self) { } } - if (!has_version_without_errors) result |= CondenseResultAllVersionsHadError; + if (!has_version_without_errors && ts_stack_version_count(self->stack) > 0) { + result |= CondenseResultAllVersionsHadError; + } + return result; } @@ -1225,6 +1228,7 @@ Tree *parser_parse(Parser *self, TSInput input, Tree *old_tree, bool halt_on_err CondenseResult condense_result = parser__condense_stack(self); if (halt_on_error && (condense_result & CondenseResultAllVersionsHadError)) { LOG("halting_parse"); + LOG_STACK(); ts_lexer_advance_to_end(&self->lexer); Length remaining_length = length_sub( diff --git a/test/runtime/document_test.cc b/test/runtime/document_test.cc index 960fe047..7757823c 100644 --- a/test/runtime/document_test.cc +++ b/test/runtime/document_test.cc @@ -396,6 +396,21 @@ describe("Document", [&]() { AssertThat(ts_node_end_char(root), Equals(input_string.size())); AssertThat(ts_node_end_byte(root), Equals(input_string.size())); }); + + it("can parse valid code with the halt_on_error flag set", [&]() { + string input_string = "[1, null, 3]"; + ts_document_set_language(document, load_real_language("json")); + ts_document_set_input_string(document, input_string.c_str()); + + TSParseOptions options; + options.changed_ranges = nullptr; + options.halt_on_error = true; + ts_document_parse_with_options(document, options); + root = ts_document_root_node(document); + assert_node_string_equals( + root, + "(array (number) (null) (number))"); + }); }); });