From 733d7513afbbe8cec6810db4f2ee0a083c2c2061 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Sat, 12 Apr 2025 12:23:16 -0700 Subject: [PATCH] fix(lib): reset parser options after use **Problem:** After `ts_parser_parse_with_options()`, the parser options are still stored in the parser object, meaning that a successive call to `ts_parser_parse()` will actually behave like `ts_parser_parse_with_options()`, which is not obvious and can have unintended consequences. **Solution:** Reset to empty options state after `ts_parser_parse_with_options()`. --- lib/src/parser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/parser.c b/lib/src/parser.c index adcdf8d0..896ea4e7 100644 --- a/lib/src/parser.c +++ b/lib/src/parser.c @@ -1540,7 +1540,7 @@ static bool ts_parser__check_progress(TSParser *self, Subtree *lookahead, const if (self->operation_count >= OP_COUNT_PER_PARSER_TIMEOUT_CHECK) { self->operation_count = 0; } - if (self->parse_options.progress_callback && position != NULL) { + if (position != NULL) { self->parse_state.current_byte_offset = *position; self->parse_state.has_error = self->has_error; } @@ -2238,6 +2238,8 @@ TSTree *ts_parser_parse_with_options( self->parse_options = parse_options; self->parse_state.payload = parse_options.payload; TSTree *result = ts_parser_parse(self, old_tree, input); + // Reset parser options before further parse calls. + self->parse_options = (TSParseOptions) {0}; return result; }