ParseItem no longer has a lookahead_sym field; it now represents the 'core' of a parse item. The lookahead context is stored separately, as a set per core item. This makes iterating, copying and merging item sets more efficient, because before, the core items were repeated for each different lookahead symbol. Also, the memoization in sym_transitions(ParseItemSet) has been removed. Maybe I'll add it back later.
33 lines
No EOL
1.1 KiB
C++
33 lines
No EOL
1.1 KiB
C++
#include "compiler_spec_helper.h"
|
|
#include "compiler/prepared_grammar.h"
|
|
#include "compiler/build_tables/item_set_closure.h"
|
|
#include "compiler/build_tables/item_set_transitions.h"
|
|
|
|
using namespace build_tables;
|
|
using namespace rules;
|
|
|
|
START_TEST
|
|
|
|
describe("computing closures of item sets", []() {
|
|
PreparedGrammar grammar({
|
|
{ "E", seq({
|
|
i_sym(1),
|
|
i_token(11) }) },
|
|
{ "T", seq({
|
|
i_token(12),
|
|
i_token(13) }) },
|
|
}, {});
|
|
|
|
it("adds items at the beginnings of referenced rules", [&]() {
|
|
ParseItemSet item_set = item_set_closure(ParseItem(Symbol(0), grammar.rule(Symbol(0)), 0),
|
|
{ Symbol(10, SymbolOptionToken) },
|
|
grammar);
|
|
|
|
AssertThat(item_set, Equals(ParseItemSet({
|
|
{ ParseItem(Symbol(1), grammar.rule(Symbol(1)), 0), { Symbol(11, SymbolOptionToken) } },
|
|
{ ParseItem(Symbol(0), grammar.rule(Symbol(0)), 0), { Symbol(10, SymbolOptionToken) } },
|
|
})));
|
|
});
|
|
});
|
|
|
|
END_TEST |