Move setup of mergeable_symbols to constructor, use set throughout
This commit is contained in:
parent
14bae584d4
commit
693c6d40dd
4 changed files with 10 additions and 12 deletions
|
|
@ -27,7 +27,7 @@ describe("recovery_tokens(rule)", []() {
|
|||
})),
|
||||
};
|
||||
|
||||
AssertThat(recovery_tokens(grammar), Equals<vector<Symbol>>({
|
||||
AssertThat(recovery_tokens(grammar), Equals<set<Symbol>>({
|
||||
Symbol(1, true),
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ class ParseTableBuilder {
|
|||
for (const auto &pair2 : state.entries)
|
||||
parse_table.symbols[pair1.first].compatible_symbols.insert(pair2.first);
|
||||
|
||||
parse_table.mergeable_symbols = recovery_tokens(lexical_grammar);
|
||||
|
||||
build_error_parse_state();
|
||||
|
||||
allow_any_conflict = true;
|
||||
|
|
@ -112,11 +114,7 @@ class ParseTableBuilder {
|
|||
void build_error_parse_state() {
|
||||
ParseState error_state;
|
||||
|
||||
auto recovery_symbols = recovery_tokens(lexical_grammar);
|
||||
|
||||
parse_table.mergeable_symbols.insert(recovery_symbols.begin(), recovery_symbols.end());
|
||||
|
||||
for (const Symbol &symbol : recovery_symbols)
|
||||
for (auto &symbol : parse_table.mergeable_symbols)
|
||||
add_out_of_context_parse_state(&error_state, symbol);
|
||||
|
||||
for (const Symbol &symbol : grammar.extra_tokens)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace tree_sitter {
|
|||
namespace build_tables {
|
||||
|
||||
using rules::Symbol;
|
||||
using std::vector;
|
||||
using std::set;
|
||||
|
||||
template <bool left, bool right>
|
||||
class CharacterAggregator : public rules::RuleFn<void> {
|
||||
|
|
@ -47,8 +47,8 @@ class FirstCharacters : public CharacterAggregator<true, false> {};
|
|||
class LastCharacters : public CharacterAggregator<false, true> {};
|
||||
class AllCharacters : public CharacterAggregator<true, true> {};
|
||||
|
||||
vector<Symbol> recovery_tokens(const LexicalGrammar &grammar) {
|
||||
vector<Symbol> result;
|
||||
set<Symbol> recovery_tokens(const LexicalGrammar &grammar) {
|
||||
set<Symbol> result;
|
||||
|
||||
AllCharacters all_separator_characters;
|
||||
for (const rule_ptr &separator : grammar.separators)
|
||||
|
|
@ -79,7 +79,7 @@ vector<Symbol> recovery_tokens(const LexicalGrammar &grammar) {
|
|||
!all_characters.result.intersects(all_separator_characters.result);
|
||||
|
||||
if ((has_distinct_start && has_distinct_end) || has_no_separators)
|
||||
result.push_back(Symbol(i, true));
|
||||
result.insert(Symbol(i, true));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "compiler/rule.h"
|
||||
#include "compiler/rules/symbol.h"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
namespace tree_sitter {
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ struct LexicalGrammar;
|
|||
|
||||
namespace build_tables {
|
||||
|
||||
std::vector<rules::Symbol> recovery_tokens(const LexicalGrammar &);
|
||||
std::set<rules::Symbol> recovery_tokens(const LexicalGrammar &);
|
||||
|
||||
} // namespace build_tables
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue