Remove the error action; a lack of actions implies an error.

This commit is contained in:
Max Brunsfeld 2016-06-21 22:53:48 -07:00
parent 6a7a5cfc3f
commit 43ae8235fd
5 changed files with 52 additions and 65 deletions

View file

@ -214,16 +214,18 @@ class CCodeGenerator {
void add_recovery_parse_states_list() {
line("static TSParseAction ts_recovery_actions[SYMBOL_COUNT] = {");
indent([&]() {
for (const auto &entry : parse_table.error_state.entries) {
if (!entry.second.actions.empty()) {
line("[" + symbol_id(entry.first) + "] = ");
ParseAction action = entry.second.actions[0];
if (action.extra) {
add("RECOVER_EXTRA(),");
} else {
for (const auto &pair : parse_table.symbols) {
const rules::Symbol &symbol = pair.first;
line("[" + symbol_id(pair.first) + "] = ");
const auto &entry = parse_table.error_state.entries.find(symbol);
if (entry != parse_table.error_state.entries.end()) {
ParseAction action = entry->second.actions[0];
if (!action.extra) {
add("RECOVER(" + to_string(action.state_index) + "),");
continue;
}
}
add("RECOVER_EXTRA(),");
}
});
line("};");
@ -231,8 +233,7 @@ class CCodeGenerator {
}
void add_parse_table() {
add_parse_action_list_id(
ParseTableEntry{ { ParseAction::Error() }, true, false });
add_parse_action_list_id(ParseTableEntry{ {}, true, false });
size_t state_id = 0;
line("#pragma GCC diagnostic push");
@ -349,7 +350,6 @@ class CCodeGenerator {
add(" ");
switch (action.type) {
case ParseActionTypeError:
add("ERROR()");
break;
case ParseActionTypeAccept:
add("ACCEPT_INPUT()");