Treat tokens that are sometimes extra as fragile
This commit is contained in:
parent
d0e107eb84
commit
66144dc28e
11 changed files with 418 additions and 403 deletions
|
|
@ -210,6 +210,8 @@ static TSTree *ts_parser__select_tree(void *data, TSTree *left, TSTree *right) {
|
|||
|
||||
static bool ts_parser__shift(TSParser *self, int head,
|
||||
TSStateId parse_state, TSTree *lookahead) {
|
||||
if (self->language->symbol_metadata[lookahead->symbol].extra)
|
||||
ts_tree_set_fragile(lookahead);
|
||||
if (ts_stack_push(self->stack, head, parse_state, lookahead)) {
|
||||
LOG("merge head:%d", head);
|
||||
vector_erase(&self->lookahead_states, head);
|
||||
|
|
@ -222,7 +224,7 @@ 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)
|
||||
if (metadata.structural && 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);
|
||||
|
|
|
|||
|
|
@ -90,6 +90,11 @@ static inline void ts_tree_set_fragile_right(TSTree *tree) {
|
|||
tree->options.fragile_right = true;
|
||||
}
|
||||
|
||||
static inline void ts_tree_set_fragile(TSTree *tree) {
|
||||
ts_tree_set_fragile_left(tree);
|
||||
ts_tree_set_fragile_right(tree);
|
||||
}
|
||||
|
||||
static inline bool ts_tree_is_fragile_left(const TSTree *tree) {
|
||||
return tree->options.fragile_left;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue