Share common lookahead sets between parse item sets
This commit is contained in:
parent
a0bf3d0bd8
commit
c4ef228397
12 changed files with 132 additions and 49 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#include "compiler/compiler_spec_helper.h"
|
||||
#include "compiler/syntax_grammar.h"
|
||||
#include "compiler/build_tables/item_set_closure.h"
|
||||
#include "compiler/build_tables/item_set_transitions.h"
|
||||
#include "compiler/build_tables/lookahead_set.h"
|
||||
#include "compiler/rules/built_in_symbols.h"
|
||||
|
||||
using namespace build_tables;
|
||||
|
|
@ -45,19 +45,19 @@ describe("item_set_closure", []() {
|
|||
AssertThat(item_set, Equals(ParseItemSet({
|
||||
{
|
||||
ParseItem(Symbol(0), 0, 0, 100),
|
||||
set<Symbol>({ Symbol(10, true) })
|
||||
LookaheadSet({ Symbol(10, true) })
|
||||
},
|
||||
{
|
||||
ParseItem(Symbol(1), 0, 0, 102),
|
||||
set<Symbol>({ Symbol(11, true) })
|
||||
LookaheadSet({ Symbol(11, true) })
|
||||
},
|
||||
{
|
||||
ParseItem(Symbol(1), 1, 0, 104),
|
||||
set<Symbol>({ Symbol(11, true) })
|
||||
LookaheadSet({ Symbol(11, true) })
|
||||
},
|
||||
{
|
||||
ParseItem(Symbol(2), 0, 0, 105),
|
||||
set<Symbol>({ Symbol(11, true) })
|
||||
LookaheadSet({ Symbol(11, true) })
|
||||
},
|
||||
})));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "compiler/compiler_spec_helper.h"
|
||||
#include "compiler/build_tables/item_set_transitions.h"
|
||||
#include "compiler/build_tables/lookahead_set.h"
|
||||
#include "compiler/syntax_grammar.h"
|
||||
#include "compiler/helpers/rule_helpers.h"
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ describe("sym_transitions(ParseItemSet, InitialSyntaxGrammar)", [&]() {
|
|||
{
|
||||
// Step 2 of rule_0's production: right before the reference to rule_1.
|
||||
ParseItem(Symbol(0), 0, 2, 103),
|
||||
set<Symbol>({ Symbol(16, true) })
|
||||
LookaheadSet({ Symbol(16, true) })
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ describe("sym_transitions(ParseItemSet, InitialSyntaxGrammar)", [&]() {
|
|||
ParseItemSet({
|
||||
{
|
||||
ParseItem(Symbol(0), 0, 3, 104),
|
||||
set<Symbol>({ Symbol(16, true) })
|
||||
LookaheadSet({ Symbol(16, true) })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
@ -92,7 +93,7 @@ describe("sym_transitions(ParseItemSet, InitialSyntaxGrammar)", [&]() {
|
|||
ParseItemSet({
|
||||
{
|
||||
ParseItem(Symbol(1), 0, 1, 106),
|
||||
set<Symbol>({ Symbol(13, true) })
|
||||
LookaheadSet({ Symbol(13, true) })
|
||||
},
|
||||
})
|
||||
},
|
||||
|
|
@ -103,7 +104,7 @@ describe("sym_transitions(ParseItemSet, InitialSyntaxGrammar)", [&]() {
|
|||
ParseItemSet({
|
||||
{
|
||||
ParseItem(Symbol(2), 0, 1, 0),
|
||||
set<Symbol>({ Symbol(14, true) })
|
||||
LookaheadSet({ Symbol(14, true) })
|
||||
},
|
||||
})
|
||||
},
|
||||
|
|
|
|||
|
|
@ -129,6 +129,10 @@ std::ostream &operator<<(std::ostream &stream, const MetadataRange &range) {
|
|||
<< to_string(range.max) << string("}");
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const LookaheadSet &set) {
|
||||
return stream << *set.entries;
|
||||
}
|
||||
|
||||
} // namespace build_tables
|
||||
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
|
|
@ -112,10 +112,12 @@ namespace build_tables {
|
|||
struct MetadataRange;
|
||||
class LexItem;
|
||||
class ParseItem;
|
||||
class LookaheadSet;
|
||||
|
||||
ostream &operator<<(ostream &, const MetadataRange &);
|
||||
ostream &operator<<(ostream &, const LexItem &);
|
||||
ostream &operator<<(ostream &, const ParseItem &);
|
||||
ostream &operator<<(ostream &, const LookaheadSet &);
|
||||
|
||||
} // namespace build_tables
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue