From 7de36a33eba1a911118623e5b5c51ada99ae17d3 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 27 Jan 2020 15:36:09 -0800 Subject: [PATCH] Remove `halt_on_error` API --- lib/binding_rust/bindings.rs | 7 ----- lib/include/tree_sitter/api.h | 8 ------ lib/src/parser.c | 49 ----------------------------------- script/build-fuzzers | 19 ++++++-------- test/fuzz/fuzzer.cc | 2 -- 5 files changed, 8 insertions(+), 77 deletions(-) diff --git a/lib/binding_rust/bindings.rs b/lib/binding_rust/bindings.rs index 75c5bb12..e1c3ceac 100644 --- a/lib/binding_rust/bindings.rs +++ b/lib/binding_rust/bindings.rs @@ -313,13 +313,6 @@ extern "C" { #[doc = " SVG output. You can turn off this logging by passing a negative number."] pub fn ts_parser_print_dot_graphs(self_: *mut TSParser, file: ::std::os::raw::c_int); } -extern "C" { - #[doc = " Set whether or not the parser should halt immediately upon detecting an"] - #[doc = " error. This will generally result in a syntax tree with an error at the"] - #[doc = " root, and one or more partial syntax trees within the error. This behavior"] - #[doc = " may not be supported long-term."] - pub fn ts_parser_halt_on_error(self_: *mut TSParser, halt: bool); -} extern "C" { #[doc = " Create a shallow copy of the syntax tree. This is very fast."] #[doc = ""] diff --git a/lib/include/tree_sitter/api.h b/lib/include/tree_sitter/api.h index 0c7b9804..9d832e6e 100644 --- a/lib/include/tree_sitter/api.h +++ b/lib/include/tree_sitter/api.h @@ -336,14 +336,6 @@ TSLogger ts_parser_logger(const TSParser *self); */ void ts_parser_print_dot_graphs(TSParser *self, int file); -/** - * Set whether or not the parser should halt immediately upon detecting an - * error. This will generally result in a syntax tree with an error at the - * root, and one or more partial syntax trees within the error. This behavior - * may not be supported long-term. - */ -void ts_parser_halt_on_error(TSParser *self, bool halt); - /******************/ /* Section - Tree */ /******************/ diff --git a/lib/src/parser.c b/lib/src/parser.c index 76bdcbfa..7d4ab930 100644 --- a/lib/src/parser.c +++ b/lib/src/parser.c @@ -71,7 +71,6 @@ struct TSParser { unsigned accept_count; unsigned operation_count; const volatile size_t *cancellation_flag; - bool halt_on_error; Subtree old_tree; TSRangeArray included_range_differences; unsigned included_range_difference_index; @@ -1067,46 +1066,6 @@ static void ts_parser__handle_error( LOG_STACK(); } -static void ts_parser__halt_parse(TSParser *self) { - LOG("halting_parse"); - LOG_STACK(); - - ts_lexer_advance_to_end(&self->lexer); - Length remaining_length = length_sub( - self->lexer.current_position, - ts_stack_position(self->stack, 0) - ); - - Subtree filler_node = ts_subtree_new_error( - &self->tree_pool, - 0, - length_zero(), - remaining_length, - remaining_length.bytes, - 0, - self->language - ); - ts_subtree_to_mut_unsafe(filler_node).ptr->visible = false; - ts_stack_push(self->stack, 0, filler_node, false, 0); - - SubtreeArray children = array_new(); - Subtree root_error = ts_subtree_new_error_node(&self->tree_pool, &children, false, self->language); - ts_stack_push(self->stack, 0, root_error, false, 0); - - Subtree eof = ts_subtree_new_leaf( - &self->tree_pool, - ts_builtin_sym_end, - length_zero(), - length_zero(), - 0, - 0, - false, - false, - self->language - ); - ts_parser__accept(self, 0, eof); -} - static bool ts_parser__recover_to_state( TSParser *self, StackVersion version, @@ -1661,7 +1620,6 @@ TSParser *ts_parser_new(void) { self->finished_tree = NULL_SUBTREE; self->reusable_node = reusable_node_new(); self->dot_graph_file = NULL; - self->halt_on_error = false; self->cancellation_flag = NULL; self->timeout_duration = 0; self->end_clock = clock_null(); @@ -1741,10 +1699,6 @@ void ts_parser_print_dot_graphs(TSParser *self, int fd) { } } -void ts_parser_halt_on_error(TSParser *self, bool should_halt_on_error) { - self->halt_on_error = should_halt_on_error; -} - const size_t *ts_parser_cancellation_flag(const TSParser *self) { return (const size_t *)self->cancellation_flag; } @@ -1862,9 +1816,6 @@ TSTree *ts_parser_parse( unsigned min_error_cost = ts_parser__condense_stack(self); if (self->finished_tree.ptr && ts_subtree_error_cost(self->finished_tree) < min_error_cost) { break; - } else if (self->halt_on_error && min_error_cost > 0) { - ts_parser__halt_parse(self); - break; } while (self->included_range_difference_index < self->included_range_differences.size) { diff --git a/script/build-fuzzers b/script/build-fuzzers index f4ddb293..c0675cd6 100755 --- a/script/build-fuzzers +++ b/script/build-fuzzers @@ -59,17 +59,14 @@ for lang in ${languages[@]}; do ts_lang_query_filename="" fi - modes=(true halt false recover) - for i in 0 2; do - # FIXME: We should extract the grammar name from grammar.js. Use the name of - # the directory instead. Also, the grammar name needs to be a valid C - # identifier so replace any '-' characters - ts_lang="tree_sitter_$(echo $lang | tr -- - _)" - $CXX $CXXFLAGS -std=c++11 -I lib/include -D TS_HALT_ON_ERROR="${modes[i]}" -D TS_LANG="$ts_lang" -D TS_LANG_QUERY_FILENAME="\"${ts_lang_query_filename}\"" \ - "test/fuzz/fuzzer.cc" "${objects[@]}" \ - libtree-sitter.a "$LIB_FUZZER_PATH" \ - -o "out/${lang}_fuzzer_${modes[i+1]}" - done + # FIXME: We should extract the grammar name from grammar.js. Use the name of + # the directory instead. Also, the grammar name needs to be a valid C + # identifier so replace any '-' characters + ts_lang="tree_sitter_$(echo $lang | tr -- - _)" + $CXX $CXXFLAGS -std=c++11 -I lib/include -D TS_LANG="$ts_lang" -D TS_LANG_QUERY_FILENAME="\"${ts_lang_query_filename}\"" \ + "test/fuzz/fuzzer.cc" "${objects[@]}" \ + libtree-sitter.a "$LIB_FUZZER_PATH" \ + -o "out/${lang}_fuzzer" python test/fuzz/gen-dict.py "${lang_dir}/src/grammar.json" > "out/$lang.dict" done diff --git a/test/fuzz/fuzzer.cc b/test/fuzz/fuzzer.cc index 2d01b2fd..ef800883 100644 --- a/test/fuzz/fuzzer.cc +++ b/test/fuzz/fuzzer.cc @@ -44,8 +44,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { bool language_ok = ts_parser_set_language(parser, TS_LANG()); assert(language_ok); - ts_parser_halt_on_error(parser, TS_HALT_ON_ERROR); - TSTree *tree = ts_parser_parse_string(parser, NULL, str, size); TSNode root_node = ts_tree_root_node(tree);