WIP: New check for mergable symbols in merge_state
This commit is contained in:
parent
82c9385518
commit
14bae584d4
3 changed files with 11 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue