Merge remote-tracking branch 'origin/master' into line-numbers
This commit is contained in:
commit
e3936e71fd
10 changed files with 3481 additions and 3979 deletions
|
|
@ -41,9 +41,12 @@ static const TSParseAction *ts_language__actions(const TSLanguage *language,
|
|||
return actions ? actions : ERROR_ACTIONS;
|
||||
}
|
||||
|
||||
static TSParseAction ts_language__action(const TSLanguage *language,
|
||||
TSStateId state, TSSymbol sym) {
|
||||
return ts_language__actions(language, state, sym)[0];
|
||||
static TSParseAction ts_language__last_action(const TSLanguage *language,
|
||||
TSStateId state, TSSymbol sym) {
|
||||
const TSParseAction *action = ts_language__actions(language, state, sym);
|
||||
while ((action + 1)->type)
|
||||
action++;
|
||||
return *action;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -107,7 +110,7 @@ static void ts_parser__get_next_lookahead(TSParser *self) {
|
|||
|
||||
TSStateId top_state = ts_stack_top_state(self->stack, 0);
|
||||
TSSymbol symbol = self->reusable_subtree->symbol;
|
||||
if (ts_language__action(self->language, top_state, symbol).type ==
|
||||
if (ts_language__last_action(self->language, top_state, symbol).type ==
|
||||
TSParseActionTypeError) {
|
||||
DEBUG("cant_reuse sym:%s", SYM_NAME(self->reusable_subtree->symbol));
|
||||
ts_parser__pop_reusable_subtree(self);
|
||||
|
|
@ -145,7 +148,8 @@ static void ts_parser__get_next_lookahead(TSParser *self) {
|
|||
* Parse Actions
|
||||
*/
|
||||
|
||||
static ConsumeResult ts_parser__shift(TSParser *self, int head, TSStateId parse_state) {
|
||||
static ConsumeResult ts_parser__shift(TSParser *self, int head,
|
||||
TSStateId parse_state) {
|
||||
if (ts_stack_push(self->stack, head, parse_state, self->lookahead))
|
||||
return ConsumeResultRemoved;
|
||||
else
|
||||
|
|
@ -186,8 +190,8 @@ static TSTree *ts_parser__reduce(TSParser *self, int head, TSSymbol symbol,
|
|||
ts_tree_set_extra(parent);
|
||||
state = top_state;
|
||||
} else {
|
||||
state =
|
||||
ts_language__action(self->language, top_state, symbol).data.to_state;
|
||||
state = ts_language__last_action(self->language, top_state, symbol)
|
||||
.data.to_state;
|
||||
}
|
||||
|
||||
ts_stack_push(self->stack, pop_result.index, state, parent);
|
||||
|
|
@ -229,15 +233,15 @@ static bool ts_parser__handle_error(TSParser *self, int head) {
|
|||
* expected and the current lookahead token is expected afterwards.
|
||||
*/
|
||||
int i = -1;
|
||||
for (StackEntry *entry = entry_before_error; entry != NULL;
|
||||
for (StackEntry *entry = entry_before_error; true;
|
||||
entry = ts_stack_entry_next(entry, head), i++) {
|
||||
TSStateId stack_state = entry->state;
|
||||
TSParseAction action_on_error =
|
||||
ts_language__action(self->language, stack_state, ts_builtin_sym_error);
|
||||
TSStateId stack_state = entry ? entry->state : 0;
|
||||
TSParseAction action_on_error = ts_language__last_action(
|
||||
self->language, stack_state, ts_builtin_sym_error);
|
||||
|
||||
if (action_on_error.type == TSParseActionTypeShift) {
|
||||
TSStateId state_after_error = action_on_error.data.to_state;
|
||||
TSParseAction action_after_error = ts_language__action(
|
||||
TSParseAction action_after_error = ts_language__last_action(
|
||||
self->language, state_after_error, self->lookahead->symbol);
|
||||
|
||||
if (action_after_error.type != TSParseActionTypeError) {
|
||||
|
|
@ -247,6 +251,9 @@ static bool ts_parser__handle_error(TSParser *self, int head) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!entry)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -382,8 +389,31 @@ static ConsumeResult ts_parser__consume_lookahead(TSParser *self, int head) {
|
|||
}
|
||||
}
|
||||
|
||||
static int ts_tree__compare(TSTree *left, TSTree *right) {
|
||||
if (left->symbol < right->symbol) return -1;
|
||||
if (right->symbol < left->symbol) return 1;
|
||||
if (left->child_count < right->child_count) return -1;
|
||||
if (right->child_count < left->child_count) return 1;
|
||||
for (size_t i = 0; i < left->child_count; i++) {
|
||||
TSTree *left_child = left->children[i];
|
||||
TSTree *right_child = right->children[i];
|
||||
switch (ts_tree__compare(left_child, right_child)) {
|
||||
case -1:
|
||||
return -1;
|
||||
case 1:
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static TSTree *ts_parser__select_tree(void *data, TSTree *left, TSTree *right) {
|
||||
return right;
|
||||
if (ts_tree__compare(left, right) <= 0)
|
||||
return left;
|
||||
else
|
||||
return right;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -124,8 +124,11 @@ static void ts_stack__add_node_successor(Stack *self, StackNode *node,
|
|||
StackNode *new_successor) {
|
||||
for (int i = 0; i < node->successor_count; i++) {
|
||||
StackNode *successor = node->successors[i];
|
||||
if (!successor)
|
||||
continue;
|
||||
if (successor == new_successor)
|
||||
return;
|
||||
|
||||
if (successor->entry.state == new_successor->entry.state) {
|
||||
if (successor->entry.tree != new_successor->entry.tree) {
|
||||
successor->entry.tree = self->tree_selection_callback.callback(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue