From 14bae584d4ff91acecbb0467bd6279e2f02407c3 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 18 Oct 2016 13:03:41 -0700 Subject: [PATCH] WIP: New check for mergable symbols in merge_state --- src/compiler/build_tables/build_parse_table.cc | 6 +++++- src/compiler/parse_table.cc | 4 ++++ src/compiler/parse_table.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compiler/build_tables/build_parse_table.cc b/src/compiler/build_tables/build_parse_table.cc index 93820424..387a1baa 100644 --- a/src/compiler/build_tables/build_parse_table.cc +++ b/src/compiler/build_tables/build_parse_table.cc @@ -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) diff --git a/src/compiler/parse_table.cc b/src/compiler/parse_table.cc index d345f0e4..b63d472b 100644 --- a/src/compiler/parse_table.cc +++ b/src/compiler/parse_table.cc @@ -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 &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)) diff --git a/src/compiler/parse_table.h b/src/compiler/parse_table.h index 1a00b273..cd24d32a 100644 --- a/src/compiler/parse_table.h +++ b/src/compiler/parse_table.h @@ -97,6 +97,8 @@ class ParseTable { std::vector states; std::map symbols; + + std::set mergeable_symbols; }; } // namespace tree_sitter