* Unify precedence/associativity-based resolution with the search for a whitelisted conflict * Improve conflict error messages
91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
#ifndef COMPILER_BUILD_TABLES_PARSE_ITEM_H_
|
|
#define COMPILER_BUILD_TABLES_PARSE_ITEM_H_
|
|
|
|
#include <map>
|
|
#include <utility>
|
|
#include "compiler/build_tables/lookahead_set.h"
|
|
#include "compiler/rules/symbol.h"
|
|
#include "compiler/rules/metadata.h"
|
|
#include "compiler/syntax_grammar.h"
|
|
#include "compiler/precedence_range.h"
|
|
|
|
namespace tree_sitter {
|
|
namespace build_tables {
|
|
|
|
class ParseItem {
|
|
public:
|
|
ParseItem();
|
|
ParseItem(const rules::Symbol &, const Production &, unsigned int);
|
|
|
|
struct CompletionStatus {
|
|
bool is_done;
|
|
int precedence;
|
|
rules::Associativity associativity;
|
|
};
|
|
|
|
bool operator==(const ParseItem &other) const;
|
|
bool operator<(const ParseItem &other) const;
|
|
rules::Symbol lhs() const;
|
|
rules::Symbol next_symbol() const;
|
|
int precedence() const;
|
|
rules::Associativity associativity() const;
|
|
bool is_done() const;
|
|
|
|
int variable_index;
|
|
const Production *production;
|
|
unsigned int step_index;
|
|
};
|
|
|
|
class ParseItemSet {
|
|
public:
|
|
ParseItemSet();
|
|
explicit ParseItemSet(const std::map<ParseItem, LookaheadSet> &);
|
|
|
|
struct Completion;
|
|
struct Action;
|
|
|
|
struct ActionMap {
|
|
std::map<rules::Symbol::Index, Action> terminal_actions;
|
|
std::map<rules::Symbol::Index, ParseItemSet> nonterminal_continuations;
|
|
};
|
|
|
|
ActionMap actions() const;
|
|
|
|
bool operator==(const ParseItemSet &) const;
|
|
void add(const ParseItemSet &);
|
|
size_t unfinished_item_signature() const;
|
|
|
|
std::map<ParseItem, LookaheadSet> entries;
|
|
};
|
|
|
|
struct ParseItemSet::Completion {
|
|
const ParseItem *item;
|
|
int precedence;
|
|
rules::Associativity associativity;
|
|
|
|
bool operator<(const ParseItemSet::Completion &other) {
|
|
return precedence < other.precedence;
|
|
}
|
|
};
|
|
|
|
struct ParseItemSet::Action {
|
|
ParseItemSet continuation;
|
|
std::vector<const ParseItem *> completions;
|
|
int completion_precedence;
|
|
};
|
|
|
|
} // namespace build_tables
|
|
} // namespace tree_sitter
|
|
|
|
namespace std {
|
|
|
|
using tree_sitter::build_tables::ParseItemSet;
|
|
|
|
template <>
|
|
struct hash<tree_sitter::build_tables::ParseItemSet> {
|
|
size_t operator()(const ParseItemSet &item_set) const;
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
#endif // COMPILER_BUILD_TABLES_PARSE_ITEM_H_
|