Remove extraneous Language methods

This commit is contained in:
Max Brunsfeld 2016-11-14 10:35:33 -08:00
parent 1118a9142a
commit 8edb8df530
2 changed files with 16 additions and 34 deletions

View file

@ -15,10 +15,9 @@ typedef struct {
bool depends_on_lookahead;
} TableEntry;
void ts_language_table_entry(const TSLanguage *, TSStateId, TSSymbol,
TableEntry *);
void ts_language_table_entry(const TSLanguage *, TSStateId, TSSymbol, TableEntry *);
bool ts_language_symbol_is_in_progress(const TSLanguage *, TSStateId, TSSymbol);
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *, TSSymbol);
static inline const TSParseAction *ts_language_actions(const TSLanguage *self,
TSStateId state,
@ -30,42 +29,26 @@ static inline const TSParseAction *ts_language_actions(const TSLanguage *self,
return entry.actions;
}
static inline const TSParseAction *ts_language_last_action(
const TSLanguage *self, TSStateId state, TSSymbol symbol) {
TableEntry entry;
ts_language_table_entry(self, state, symbol, &entry);
if (entry.action_count)
return &entry.actions[entry.action_count - 1];
else
return NULL;
}
static inline TSStateId ts_language_next_state(const TSLanguage *self,
TSStateId state,
TSSymbol symbol) {
if (symbol == ts_builtin_sym_error) {
return 0;
} else if (symbol < self->token_count) {
const TSParseAction *action = ts_language_last_action(self, state, symbol);
if (action && (action->type == TSParseActionTypeShift || action->type == TSParseActionTypeRecover)) {
return action->params.to_state;
} else {
return 0;
size_t count;
const TSParseAction *actions = ts_language_actions(self, state, symbol, &count);
if (count > 0) {
TSParseAction action = actions[count - 1];
if (action.type == TSParseActionTypeShift || action.type == TSParseActionTypeRecover) {
return action.params.to_state;
}
}
return 0;
} else {
return self->parse_table[state * self->symbol_count + symbol];
}
}
static inline bool ts_language_is_reusable(const TSLanguage *self,
TSStateId state, TSSymbol symbol) {
TableEntry entry;
ts_language_table_entry(self, state, symbol, &entry);
return entry.is_reusable;
}
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *, TSSymbol);
#ifdef __cplusplus
}
#endif

View file

@ -600,8 +600,12 @@ static StackIterateAction parser__error_repair_callback(
}
TSStateId state_after_repair = ts_language_next_state(self->language, state, repair->symbol);
if (state == ERROR_STATE || state_after_repair == ERROR_STATE ||
!ts_language_last_action(self->language, state_after_repair, lookahead_symbol))
if (state == ERROR_STATE || state_after_repair == ERROR_STATE)
continue;
size_t action_count;
ts_language_actions(self->language, state_after_repair, lookahead_symbol, &action_count);
if (action_count == 0)
continue;
if (count_needed_below_error != last_repair_count) {
@ -1030,7 +1034,6 @@ static void parser__advance(Parser *self, StackVersion version,
LOG("accept");
parser__accept(self, version, lookahead);
ts_tree_release(lookahead);
return;
}
@ -1042,14 +1045,10 @@ static void parser__advance(Parser *self, StackVersion version,
lookahead = reusable_node->tree;
ts_tree_retain(lookahead);
}
action =
*ts_language_last_action(self->language, state, lookahead->symbol);
parser__recover(self, version, action.params.to_state, lookahead);
if (lookahead == reusable_node->tree)
parser__pop_reusable_node(reusable_node);
ts_tree_release(lookahead);
return;
}