Compute parse state group signature based on the item set
This commit is contained in:
parent
42d37656ea
commit
6cfd009503
5 changed files with 29 additions and 76 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#include <string>
|
||||
#include "compiler/syntax_grammar.h"
|
||||
#include "compiler/rules/built_in_symbols.h"
|
||||
#include "compiler/util/hash_combine.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace build_tables {
|
||||
|
|
@ -12,6 +13,9 @@ using std::string;
|
|||
using std::to_string;
|
||||
using std::hash;
|
||||
using rules::Symbol;
|
||||
using util::hash_combine;
|
||||
|
||||
ParseItem::ParseItem() : variable_index(-1), production(nullptr), step_index(0) {}
|
||||
|
||||
ParseItem::ParseItem(const Symbol &lhs, const Production &production,
|
||||
unsigned int step_index)
|
||||
|
|
@ -108,6 +112,23 @@ size_t ParseItemSet::Hash::operator()(const ParseItemSet &item_set) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
size_t ParseItemSet::unfinished_item_signature() const {
|
||||
size_t result = 0;
|
||||
ParseItem previous_item;
|
||||
for (auto &pair : entries) {
|
||||
const ParseItem &item = pair.first;
|
||||
if (item.step_index < item.production->size()) {
|
||||
if (item.variable_index != previous_item.variable_index &&
|
||||
item.step_index != previous_item.step_index) {
|
||||
hash_combine(&result, item.variable_index);
|
||||
hash_combine(&result, item.step_index);
|
||||
previous_item = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ParseItemSet::TransitionMap ParseItemSet::transitions() const {
|
||||
ParseItemSet::TransitionMap result;
|
||||
for (const auto &pair : entries) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue