Discard tokens after error detection to find the best repair
* Use GLR stack-splitting to try all numbers of tokens to discard until a repair is found. * Check the validity of repairs by looking at the child trees, rather than the statically-computed 'in-progress symbols' list
This commit is contained in:
parent
9d247e45b2
commit
22c550c9d6
21 changed files with 454 additions and 506 deletions
|
|
@ -1,32 +1,33 @@
|
|||
#include "tree_sitter/parser.h"
|
||||
#include "runtime/language.h"
|
||||
#include "runtime/tree.h"
|
||||
|
||||
const TSParseAction *ts_language_actions(const TSLanguage *language,
|
||||
TSStateId state, TSSymbol symbol,
|
||||
size_t *count) {
|
||||
size_t action_index = 0;
|
||||
if (symbol != ts_builtin_sym_error) {
|
||||
if (state == ts_parse_state_error)
|
||||
state = language->recovery_states[symbol];
|
||||
action_index =
|
||||
(language->parse_table + (state * language->symbol_count))[symbol];
|
||||
const TSParseAction *ts_language_actions(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol symbol, size_t *count) {
|
||||
if (state == ts_parse_state_error) {
|
||||
*count = 1;
|
||||
return &self->recovery_actions[symbol];
|
||||
}
|
||||
|
||||
*count = language->parse_actions[action_index].count;
|
||||
const TSParseActionEntry *entry = language->parse_actions + action_index + 1;
|
||||
size_t action_index = 0;
|
||||
if (symbol != ts_builtin_sym_error)
|
||||
action_index = self->parse_table[state * self->symbol_count + symbol];
|
||||
|
||||
*count = self->parse_actions[action_index].count;
|
||||
const TSParseActionEntry *entry = self->parse_actions + action_index + 1;
|
||||
return (const TSParseAction *)entry;
|
||||
}
|
||||
|
||||
TSParseAction ts_language_last_action(const TSLanguage *language,
|
||||
TSStateId state, TSSymbol sym) {
|
||||
TSParseAction ts_language_last_action(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol sym) {
|
||||
size_t count;
|
||||
const TSParseAction *actions =
|
||||
ts_language_actions(language, state, sym, &count);
|
||||
const TSParseAction *actions = ts_language_actions(self, state, sym, &count);
|
||||
return actions[count - 1];
|
||||
}
|
||||
|
||||
bool ts_language_has_action(const TSLanguage *language, TSStateId state,
|
||||
bool ts_language_has_action(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol symbol) {
|
||||
TSParseAction action = ts_language_last_action(language, state, symbol);
|
||||
TSParseAction action = ts_language_last_action(self, state, symbol);
|
||||
return action.type != TSParseActionTypeError;
|
||||
}
|
||||
|
||||
|
|
@ -50,16 +51,3 @@ const char *ts_language_symbol_name(const TSLanguage *language, TSSymbol symbol)
|
|||
else
|
||||
return language->symbol_names[symbol];
|
||||
}
|
||||
|
||||
bool ts_language_symbol_is_in_progress(const TSLanguage *self, TSStateId state,
|
||||
TSSymbol symbol) {
|
||||
if (state == ts_parse_state_error)
|
||||
return false;
|
||||
unsigned index = self->in_progress_symbol_table[state];
|
||||
unsigned short count = self->in_progress_symbols[index].count;
|
||||
const TSInProgressSymbolEntry *entries = self->in_progress_symbols + index + 1;
|
||||
for (size_t i = 0; i < count; i++)
|
||||
if (entries[i].symbol == symbol)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue