Don't mutate shared lookahead nodes when setting the extra flag
This commit is contained in:
parent
71059f1d66
commit
3c3d95345f
3 changed files with 10 additions and 0 deletions
|
|
@ -221,6 +221,9 @@ static bool ts_parser__shift(TSParser *self, int head,
|
|||
|
||||
static bool ts_parser__shift_extra(TSParser *self, int head, TSStateId state,
|
||||
TSTree *lookahead) {
|
||||
TSSymbolMetadata metadata = self->language->symbol_metadata[lookahead->symbol];
|
||||
if (!metadata.extra && ts_stack_head_count(self->stack) > 1)
|
||||
lookahead = ts_tree_make_copy(lookahead);
|
||||
ts_tree_set_extra(lookahead);
|
||||
return ts_parser__shift(self, head, state, lookahead);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,12 @@ TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_char)
|
|||
return result;
|
||||
}
|
||||
|
||||
TSTree *ts_tree_make_copy(TSTree *self) {
|
||||
TSTree *result = malloc(sizeof(TSTree));
|
||||
*result = *self;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ts_tree_assign_parents(TSTree *self) {
|
||||
TSLength offset = ts_length_zero();
|
||||
for (size_t i = 0; i < self->child_count; i++) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ struct TSTree {
|
|||
|
||||
TSTree *ts_tree_make_leaf(TSSymbol, TSLength, TSLength, TSSymbolMetadata);
|
||||
TSTree *ts_tree_make_node(TSSymbol, size_t, TSTree **, TSSymbolMetadata);
|
||||
TSTree *ts_tree_make_copy(TSTree *child);
|
||||
TSTree *ts_tree_make_error(TSLength, TSLength, char);
|
||||
void ts_tree_retain(TSTree *tree);
|
||||
void ts_tree_release(TSTree *tree);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue