Remove 'extra' and 'structural' booleans from symbol metadata
This commit is contained in:
parent
d342b61ede
commit
b0fdc33f73
6 changed files with 15 additions and 36 deletions
|
|
@ -136,8 +136,7 @@ class CCodeGenerator {
|
|||
|
||||
void add_stats() {
|
||||
size_t token_count = 0;
|
||||
for (const auto &entry : parse_table.symbols) {
|
||||
const Symbol &symbol = entry.first;
|
||||
for (const Symbol &symbol : parse_table.symbols) {
|
||||
if (symbol.is_terminal()) {
|
||||
token_count++;
|
||||
} else if (symbol.is_external()) {
|
||||
|
|
@ -170,8 +169,7 @@ class CCodeGenerator {
|
|||
line("enum {");
|
||||
indent([&]() {
|
||||
size_t i = 1;
|
||||
for (const auto &entry : parse_table.symbols) {
|
||||
const Symbol &symbol = entry.first;
|
||||
for (const Symbol &symbol : parse_table.symbols) {
|
||||
if (!symbol.is_built_in()) {
|
||||
line(symbol_id(symbol) + " = " + to_string(i) + ",");
|
||||
i++;
|
||||
|
|
@ -190,10 +188,10 @@ class CCodeGenerator {
|
|||
void add_symbol_names_list() {
|
||||
line("static const char *ts_symbol_names[] = {");
|
||||
indent([&]() {
|
||||
for (const auto &entry : parse_table.symbols) {
|
||||
for (const Symbol &symbol : parse_table.symbols) {
|
||||
line(
|
||||
"[" + symbol_id(entry.first) + "] = \"" +
|
||||
sanitize_name_for_string(symbol_name(entry.first)) + "\","
|
||||
"[" + symbol_id(symbol) + "] = \"" +
|
||||
sanitize_name_for_string(symbol_name(symbol)) + "\","
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -236,8 +234,7 @@ class CCodeGenerator {
|
|||
void add_symbol_metadata_list() {
|
||||
line("static const TSSymbolMetadata ts_symbol_metadata[] = {");
|
||||
indent([&]() {
|
||||
for (const auto &entry : parse_table.symbols) {
|
||||
const Symbol &symbol = entry.first;
|
||||
for (const Symbol &symbol : parse_table.symbols) {
|
||||
line("[" + symbol_id(symbol) + "] = {");
|
||||
indent([&]() {
|
||||
switch (symbol_type(symbol)) {
|
||||
|
|
@ -258,9 +255,6 @@ class CCodeGenerator {
|
|||
line(".named = false,");
|
||||
break;
|
||||
}
|
||||
|
||||
line(".structural = " + _boolean(entry.second.structural) + ",");
|
||||
line(".extra = " + _boolean(entry.second.extra) + ",");
|
||||
});
|
||||
|
||||
line("},");
|
||||
|
|
@ -271,8 +265,6 @@ class CCodeGenerator {
|
|||
indent([&]() {
|
||||
line(".visible = true,");
|
||||
line(".named = " + _boolean(alias.is_named) + ",");
|
||||
line(".structural = true,");
|
||||
line(".extra = true,");
|
||||
});
|
||||
line("},");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,11 +146,7 @@ bool ParseState::operator==(const ParseState &other) const {
|
|||
ParseAction &ParseTable::add_terminal_action(ParseStateId state_id,
|
||||
Symbol lookahead,
|
||||
ParseAction action) {
|
||||
if (action.type == ParseActionTypeShift && action.extra)
|
||||
symbols[lookahead].extra = true;
|
||||
else
|
||||
symbols[lookahead].structural = true;
|
||||
|
||||
symbols.insert(lookahead);
|
||||
ParseTableEntry &entry = states[state_id].terminal_entries[lookahead];
|
||||
entry.actions.push_back(action);
|
||||
return *entry.actions.rbegin();
|
||||
|
|
@ -159,7 +155,7 @@ ParseAction &ParseTable::add_terminal_action(ParseStateId state_id,
|
|||
void ParseTable::set_nonterminal_action(ParseStateId state_id,
|
||||
Symbol::Index lookahead,
|
||||
ParseStateId next_state_id) {
|
||||
symbols[Symbol::non_terminal(lookahead)].structural = true;
|
||||
symbols.insert(Symbol::non_terminal(lookahead));
|
||||
states[state_id].nonterminal_entries[lookahead] = next_state_id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,11 +72,6 @@ struct ParseState {
|
|||
LexStateId lex_state_id;
|
||||
};
|
||||
|
||||
struct ParseTableSymbolMetadata {
|
||||
bool extra;
|
||||
bool structural;
|
||||
};
|
||||
|
||||
using AliasSequence = std::vector<rules::Alias>;
|
||||
|
||||
struct ParseTable {
|
||||
|
|
@ -84,7 +79,7 @@ struct ParseTable {
|
|||
void set_nonterminal_action(ParseStateId, rules::Symbol::Index, ParseStateId);
|
||||
|
||||
std::vector<ParseState> states;
|
||||
std::map<rules::Symbol, ParseTableSymbolMetadata> symbols;
|
||||
std::set<rules::Symbol> symbols;
|
||||
std::vector<AliasSequence> alias_sequences;
|
||||
unsigned max_alias_sequence_length = 0;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue