Represent ParseItemSets as ordered maps
This way, reductions will be added in a deterministic order when constructing the parse table.
This commit is contained in:
parent
929897a78e
commit
d6a6b0a19b
3 changed files with 12 additions and 3 deletions
|
|
@ -20,6 +20,14 @@ bool ParseItem::operator==(const ParseItem &other) const {
|
|||
(rule == other.rule || rule->operator==(*other.rule));
|
||||
}
|
||||
|
||||
bool ParseItem::operator<(const ParseItem &other) const {
|
||||
if (lhs < other.lhs) return true;
|
||||
if (other.lhs < lhs) return false;
|
||||
if (consumed_symbols.size() < other.consumed_symbols.size()) return true;
|
||||
if (other.consumed_symbols.size() < consumed_symbols.size()) return false;
|
||||
return rule < other.rule;
|
||||
}
|
||||
|
||||
rules::Associativity ParseItem::associativity() const {
|
||||
return rules::Associativity(get_metadata(rule, rules::ASSOCIATIVITY));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define COMPILER_BUILD_TABLES_PARSE_ITEM_H_
|
||||
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "compiler/build_tables/item.h"
|
||||
#include "compiler/rules/symbol.h"
|
||||
|
|
@ -16,13 +16,14 @@ class ParseItem : public Item {
|
|||
ParseItem(const rules::Symbol &lhs, rules::rule_ptr rule,
|
||||
const std::vector<rules::Symbol> &consumed_symbols);
|
||||
bool operator==(const ParseItem &other) const;
|
||||
bool operator<(const ParseItem &other) const;
|
||||
rules::Associativity associativity() const;
|
||||
std::vector<rules::Symbol> consumed_symbols;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const ParseItem &item);
|
||||
|
||||
typedef std::unordered_map<ParseItem, std::set<rules::Symbol>> ParseItemSet;
|
||||
typedef std::map<ParseItem, std::set<rules::Symbol>> ParseItemSet;
|
||||
|
||||
} // namespace build_tables
|
||||
} // namespace tree_sitter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue