Skip to content

Commit 733d751

Browse files
ribru17WillLillis
authored andcommitted
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()`.
1 parent b341073 commit 733d751

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/src/parser.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ static bool ts_parser__check_progress(TSParser *self, Subtree *lookahead, const
15401540
if (self->operation_count >= OP_COUNT_PER_PARSER_TIMEOUT_CHECK) {
15411541
self->operation_count = 0;
15421542
}
1543-
if (self->parse_options.progress_callback && position != NULL) {
1543+
if (position != NULL) {
15441544
self->parse_state.current_byte_offset = *position;
15451545
self->parse_state.has_error = self->has_error;
15461546
}
@@ -2238,6 +2238,8 @@ TSTree *ts_parser_parse_with_options(
22382238
self->parse_options = parse_options;
22392239
self->parse_state.payload = parse_options.payload;
22402240
TSTree *result = ts_parser_parse(self, old_tree, input);
2241+
// Reset parser options before further parse calls.
2242+
self->parse_options = (TSParseOptions) {0};
22412243
return result;
22422244
}
22432245

0 commit comments

Comments
 (0)