Remove unused parameters to ParseConflictManager
This commit is contained in:
parent
da115d81a4
commit
351b4f4aaa
4 changed files with 27 additions and 46 deletions
|
|
@ -9,41 +9,32 @@ using namespace build_tables;
|
|||
START_TEST
|
||||
|
||||
describe("ParseConflictManager", []() {
|
||||
SyntaxGrammar syntax_grammar{{
|
||||
SyntaxVariable("in_progress_rule1", VariableTypeNamed, { Production() }),
|
||||
SyntaxVariable("in_progress_rule2", VariableTypeNamed, { Production() }),
|
||||
SyntaxVariable("reduced_rule", VariableTypeNamed, { Production() }),
|
||||
SyntaxVariable("other_rule1", VariableTypeNamed, { Production() }),
|
||||
SyntaxVariable("other_rule2", VariableTypeNamed, { Production() }),
|
||||
}, { Symbol(2, true) }, {}};
|
||||
|
||||
pair<bool, ConflictType> result;
|
||||
Symbol sym1(0);
|
||||
Symbol sym2(1);
|
||||
Symbol lookahead_sym(1, true);
|
||||
const Production production;
|
||||
ParseConflictManager *conflict_manager;
|
||||
|
||||
before_each([&]() {
|
||||
conflict_manager = new ParseConflictManager(syntax_grammar);
|
||||
conflict_manager = new ParseConflictManager;
|
||||
});
|
||||
|
||||
after_each([&]() {
|
||||
delete conflict_manager;
|
||||
});
|
||||
|
||||
const Production &production = syntax_grammar.variables[0].productions[0];
|
||||
|
||||
describe(".resolve", [&]() {
|
||||
describe("errors", [&]() {
|
||||
ParseAction error = ParseAction::Error();
|
||||
ParseAction non_error = ParseAction::Shift(2, { 0, 0 });
|
||||
|
||||
it("favors non-errors and reports no conflict", [&]() {
|
||||
result = conflict_manager->resolve(non_error, error, sym1);
|
||||
result = conflict_manager->resolve(non_error, error);
|
||||
AssertThat(result.first, IsTrue());
|
||||
AssertThat(result.second, Equals(ConflictTypeNone));
|
||||
|
||||
result = conflict_manager->resolve(error, non_error, sym1);
|
||||
result = conflict_manager->resolve(error, non_error);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeNone));
|
||||
});
|
||||
|
|
@ -54,11 +45,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction other = ParseAction::Shift(2, { 0, 0 });
|
||||
|
||||
it("favors other actions over shift-extra actions", [&]() {
|
||||
result = conflict_manager->resolve(other, shift_extra, sym1);
|
||||
result = conflict_manager->resolve(other, shift_extra);
|
||||
AssertThat(result.first, IsTrue());
|
||||
AssertThat(result.second, Equals(ConflictTypeNone));
|
||||
|
||||
result = conflict_manager->resolve(shift_extra, other, sym1);
|
||||
result = conflict_manager->resolve(shift_extra, other);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeNone));
|
||||
});
|
||||
|
|
@ -70,11 +61,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction reduce = ParseAction::Reduce(sym2, 1, 2, AssociativityLeft, production);
|
||||
|
||||
it("favors the shift and reports the conflict as resolved", [&]() {
|
||||
result = conflict_manager->resolve(shift, reduce, sym1);
|
||||
result = conflict_manager->resolve(shift, reduce);
|
||||
AssertThat(result.first, IsTrue());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
|
||||
result = conflict_manager->resolve(reduce, shift, sym1);
|
||||
result = conflict_manager->resolve(reduce, shift);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
});
|
||||
|
|
@ -85,11 +76,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction reduce = ParseAction::Reduce(sym2, 1, 3, AssociativityLeft, production);
|
||||
|
||||
it("favors the reduce and reports the conflict as resolved", [&]() {
|
||||
result = conflict_manager->resolve(shift, reduce, sym1);
|
||||
result = conflict_manager->resolve(shift, reduce);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
|
||||
result = conflict_manager->resolve(reduce, shift, sym1);
|
||||
result = conflict_manager->resolve(reduce, shift);
|
||||
AssertThat(result.first, IsTrue());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
});
|
||||
|
|
@ -100,11 +91,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction reduce = ParseAction::Reduce(sym2, 1, 0, AssociativityLeft, production);
|
||||
|
||||
it("favors the reduce and reports the conflict as resolved", [&]() {
|
||||
result = conflict_manager->resolve(reduce, shift, sym1);
|
||||
result = conflict_manager->resolve(reduce, shift);
|
||||
AssertThat(result.first, IsTrue());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
|
||||
result = conflict_manager->resolve(shift, reduce, sym1);
|
||||
result = conflict_manager->resolve(shift, reduce);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
});
|
||||
|
|
@ -115,11 +106,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction reduce = ParseAction::Reduce(sym2, 1, 0, AssociativityRight, production);
|
||||
|
||||
it("favors the shift, and reports the conflict as resolved", [&]() {
|
||||
result = conflict_manager->resolve(reduce, shift, sym1);
|
||||
result = conflict_manager->resolve(reduce, shift);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
|
||||
result = conflict_manager->resolve(shift, reduce, sym1);
|
||||
result = conflict_manager->resolve(shift, reduce);
|
||||
AssertThat(result.first, IsTrue());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
});
|
||||
|
|
@ -130,11 +121,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction shift = ParseAction::Shift(2, { 0, 0 });
|
||||
ParseAction reduce = ParseAction::Reduce(Symbol(2), 1, 0, AssociativityNone, production);
|
||||
|
||||
result = conflict_manager->resolve(reduce, shift, lookahead_sym);
|
||||
result = conflict_manager->resolve(reduce, shift);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeUnresolved));
|
||||
|
||||
result = conflict_manager->resolve(shift, reduce, lookahead_sym);
|
||||
result = conflict_manager->resolve(shift, reduce);
|
||||
AssertThat(result.first, IsTrue());
|
||||
});
|
||||
});
|
||||
|
|
@ -144,11 +135,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction reduce = ParseAction::Reduce(Symbol(2), 1, 2, AssociativityLeft, production);
|
||||
|
||||
it("returns false and reports an unresolved conflict", [&]() {
|
||||
result = conflict_manager->resolve(reduce, shift, lookahead_sym);
|
||||
result = conflict_manager->resolve(reduce, shift);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeUnresolved));
|
||||
|
||||
result = conflict_manager->resolve(shift, reduce, lookahead_sym);
|
||||
result = conflict_manager->resolve(shift, reduce);
|
||||
AssertThat(result.first, IsTrue());
|
||||
AssertThat(result.second, Equals(ConflictTypeUnresolved));
|
||||
});
|
||||
|
|
@ -161,11 +152,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction right = ParseAction::Reduce(sym2, 1, 2, AssociativityLeft, production);
|
||||
|
||||
it("favors that action", [&]() {
|
||||
result = conflict_manager->resolve(left, right, sym1);
|
||||
result = conflict_manager->resolve(left, right);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
|
||||
result = conflict_manager->resolve(right, left, sym1);
|
||||
result = conflict_manager->resolve(right, left);
|
||||
AssertThat(result.first, IsTrue());
|
||||
AssertThat(result.second, Equals(ConflictTypeResolved));
|
||||
});
|
||||
|
|
@ -176,11 +167,11 @@ describe("ParseConflictManager", []() {
|
|||
ParseAction left = ParseAction::Reduce(Symbol(2), 1, 0, AssociativityLeft, production);
|
||||
ParseAction right = ParseAction::Reduce(Symbol(3), 1, 0, AssociativityLeft, production);
|
||||
|
||||
result = conflict_manager->resolve(right, left, lookahead_sym);
|
||||
result = conflict_manager->resolve(right, left);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeUnresolved));
|
||||
|
||||
result = conflict_manager->resolve(left, right, lookahead_sym);
|
||||
result = conflict_manager->resolve(left, right);
|
||||
AssertThat(result.first, IsFalse());
|
||||
AssertThat(result.second, Equals(ConflictTypeUnresolved));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,8 +43,7 @@ class ParseTableBuilder {
|
|||
ParseTableBuilder(const SyntaxGrammar &grammar,
|
||||
const LexicalGrammar &lex_grammar)
|
||||
: grammar(grammar),
|
||||
lexical_grammar(lex_grammar),
|
||||
conflict_manager(grammar) {}
|
||||
lexical_grammar(lex_grammar) {}
|
||||
|
||||
pair<ParseTable, const GrammarError *> build() {
|
||||
Symbol start_symbol = Symbol(0, grammar.variables.empty());
|
||||
|
|
@ -247,8 +246,7 @@ class ParseTableBuilder {
|
|||
return &parse_table.set_action(state_id, lookahead, new_action);
|
||||
|
||||
const ParseAction old_action = current_entry->second[0];
|
||||
auto resolution =
|
||||
conflict_manager.resolve(new_action, old_action, lookahead);
|
||||
auto resolution = conflict_manager.resolve(new_action, old_action);
|
||||
|
||||
switch (resolution.second) {
|
||||
case ConflictTypeNone:
|
||||
|
|
|
|||
|
|
@ -9,14 +9,10 @@ namespace build_tables {
|
|||
using std::pair;
|
||||
using std::vector;
|
||||
|
||||
ParseConflictManager::ParseConflictManager(const SyntaxGrammar &syntax_grammar)
|
||||
: syntax_grammar(syntax_grammar) {}
|
||||
|
||||
pair<bool, ConflictType> ParseConflictManager::resolve(
|
||||
const ParseAction &new_action, const ParseAction &old_action,
|
||||
const rules::Symbol &symbol) const {
|
||||
const ParseAction &new_action, const ParseAction &old_action) const {
|
||||
if (new_action.type < old_action.type) {
|
||||
auto opposite = resolve(old_action, new_action, symbol);
|
||||
auto opposite = resolve(old_action, new_action);
|
||||
return { !opposite.first, opposite.second };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,8 @@ enum ConflictType {
|
|||
};
|
||||
|
||||
class ParseConflictManager {
|
||||
const SyntaxGrammar syntax_grammar;
|
||||
|
||||
public:
|
||||
explicit ParseConflictManager(const SyntaxGrammar &);
|
||||
std::pair<bool, ConflictType> resolve(const ParseAction &, const ParseAction &,
|
||||
const rules::Symbol &) const;
|
||||
std::pair<bool, ConflictType> resolve(const ParseAction &, const ParseAction &) const;
|
||||
};
|
||||
|
||||
} // namespace build_tables
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue