In parse table, store symbols as Symbol objects, not strings

This commit is contained in:
Max Brunsfeld 2014-01-27 12:40:06 -08:00
parent 0877d01194
commit ca33c3942a
20 changed files with 262 additions and 262 deletions

View file

@ -4,7 +4,7 @@
#include <unordered_map>
#include <vector>
#include <unordered_set>
#include "rule.h"
#include "symbol.h"
namespace tree_sitter {
typedef enum {
@ -15,17 +15,17 @@ namespace tree_sitter {
} ParseActionType;
class ParseAction {
ParseAction(ParseActionType type, size_t state_index, std::string symbol_name, size_t child_symbol_count);
ParseAction(ParseActionType type, size_t state_index, rules::Symbol symbol, size_t child_symbol_count);
public:
static ParseAction Accept();
static ParseAction Error();
static ParseAction Shift(size_t state_index);
static ParseAction Reduce(std::string symbol_name, size_t child_symbol_count);
static ParseAction Reduce(rules::Symbol symbol, size_t child_symbol_count);
bool operator==(const ParseAction &action) const;
ParseActionType type;
size_t child_symbol_count;
std::string symbol_name;
rules::Symbol symbol;
size_t state_index;
};
@ -38,7 +38,7 @@ namespace std {
size_t operator()(const tree_sitter::ParseAction &action) const {
return (
hash<int>()(action.type) ^
hash<string>()(action.symbol_name) ^
hash<tree_sitter::rules::Symbol>()(action.symbol) ^
hash<size_t>()(action.state_index) ^
hash<size_t>()(action.child_symbol_count));
}
@ -49,8 +49,8 @@ namespace tree_sitter {
class ParseState {
public:
ParseState();
std::unordered_map<std::string, std::unordered_set<ParseAction>> actions;
std::unordered_set<std::string> expected_inputs() const;
std::unordered_map<rules::Symbol, std::unordered_set<ParseAction>> actions;
std::unordered_set<rules::Symbol> expected_inputs() const;
size_t lex_state_index;
};
@ -59,10 +59,10 @@ namespace tree_sitter {
class ParseTable {
public:
size_t add_state();
void add_action(size_t state_index, std::string symbol_name, ParseAction action);
void add_action(size_t state_index, rules::Symbol symbol, ParseAction action);
std::vector<ParseState> states;
std::unordered_set<std::string> symbol_names;
std::unordered_set<rules::Symbol> symbols;
};
}