WIP: New check for mergable symbols in merge_state

This commit is contained in:
Timothy Clem 2016-10-18 13:03:41 -07:00
parent 82c9385518
commit 14bae584d4
3 changed files with 11 additions and 1 deletions

View file

@ -112,7 +112,11 @@ class ParseTableBuilder {
void build_error_parse_state() {
ParseState error_state;
for (const Symbol &symbol : recovery_tokens(lexical_grammar))
auto recovery_symbols = recovery_tokens(lexical_grammar);
parse_table.mergeable_symbols.insert(recovery_symbols.begin(), recovery_symbols.end());
for (const Symbol &symbol : recovery_symbols)
add_out_of_context_parse_state(&error_state, symbol);
for (const Symbol &symbol : grammar.extra_tokens)

View file

@ -206,6 +206,8 @@ bool ParseTable::merge_state(size_t i, size_t j) {
const auto &other_entry = other.entries.find(symbol);
if (other_entry == other.entries.end()) {
if (mergeable_symbols.count(symbol) == 0)
return false;
if (actions.back().type != ParseActionTypeReduce)
return false;
if (!has_entry(other, entry.second))
@ -222,6 +224,8 @@ bool ParseTable::merge_state(size_t i, size_t j) {
const vector<ParseAction> &actions = entry.second.actions;
if (!state.entries.count(symbol)) {
if (mergeable_symbols.count(symbol) == 0)
return false;
if (actions.back().type != ParseActionTypeReduce)
return false;
if (!has_entry(state, entry.second))

View file

@ -97,6 +97,8 @@ class ParseTable {
std::vector<ParseState> states;
std::map<rules::Symbol, ParseTableSymbolMetadata> symbols;
std::set<rules::Symbol> mergeable_symbols;
};
} // namespace tree_sitter