Generate C code for out-of-context states
This commit is contained in:
parent
8c01b70ce7
commit
00d953f507
3 changed files with 31 additions and 9 deletions
|
|
@ -98,6 +98,7 @@ class CCodeGenerator {
|
|||
add_symbol_node_types_list();
|
||||
add_lex_function();
|
||||
add_lex_states_list();
|
||||
add_out_of_context_parse_states_list();
|
||||
add_parse_table();
|
||||
add_parser_export();
|
||||
|
||||
|
|
@ -216,6 +217,21 @@ class CCodeGenerator {
|
|||
line();
|
||||
}
|
||||
|
||||
void add_out_of_context_parse_states_list() {
|
||||
line("static TSStateId ts_out_of_context_states[SYMBOL_COUNT] = {");
|
||||
indent([&]() {
|
||||
for (const auto &entry : parse_table.symbols) {
|
||||
const rules::Symbol &symbol = entry.first;
|
||||
ParseStateId state = parse_table.out_of_context_state_indices.find(symbol)->second;
|
||||
if (symbol.is_token && !symbol.is_built_in()) {
|
||||
line("[" + symbol_id(symbol) + "] = " + to_string(state) + ",");
|
||||
}
|
||||
}
|
||||
});
|
||||
line("};");
|
||||
line();
|
||||
}
|
||||
|
||||
void add_parse_table() {
|
||||
add_parse_actions({ ParseAction::Error() });
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue