fix(lib): prevent finished_tree assertion failure
**Problem:** When resetting the parser during subtree balancing, an error is thrown: ``` parser.c:2198: ts_parser_parse: Assertion `self->finished_tree.ptr' failed. ``` **Solution:** Reset `canceled_balancing` to false in `ts_parser_reset()`.
This commit is contained in:
parent
ac8a4ba80e
commit
9ad096ef22
2 changed files with 26 additions and 0 deletions
|
|
@ -1004,6 +1004,31 @@ fn test_parsing_with_timeout_during_balancing() {
|
|||
assert!(tree.is_none());
|
||||
assert!(in_balancing);
|
||||
|
||||
// This should not cause an assertion failure.
|
||||
parser.reset();
|
||||
let tree = parser.parse_with_options(
|
||||
&mut |offset, _| {
|
||||
if offset >= code.len() {
|
||||
&[]
|
||||
} else {
|
||||
&code.as_bytes()[offset..]
|
||||
}
|
||||
},
|
||||
None,
|
||||
Some(ParseOptions::new().progress_callback(&mut |state| {
|
||||
if state.current_byte_offset() != current_byte_offset {
|
||||
current_byte_offset = state.current_byte_offset();
|
||||
false
|
||||
} else {
|
||||
in_balancing = true;
|
||||
true
|
||||
}
|
||||
})),
|
||||
);
|
||||
|
||||
assert!(tree.is_none());
|
||||
assert!(in_balancing);
|
||||
|
||||
// If we resume parsing (implying we didn't call `parser.reset()`), we should be able to
|
||||
// finish parsing the tree, continuing from where we left off.
|
||||
let tree = parser
|
||||
|
|
|
|||
|
|
@ -2080,6 +2080,7 @@ void ts_parser_reset(TSParser *self) {
|
|||
self->accept_count = 0;
|
||||
self->has_scanner_error = false;
|
||||
self->has_error = false;
|
||||
self->canceled_balancing = false;
|
||||
self->parse_options = (TSParseOptions) {0};
|
||||
self->parse_state = (TSParseState) {0};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue