Fix ParseStateId / size_t confusion in parse table

This commit is contained in:
Max Brunsfeld 2014-07-07 13:21:30 -07:00
parent c5c25d30bb
commit f4287c07d0
3 changed files with 12 additions and 12 deletions

View file

@ -92,7 +92,7 @@ namespace tree_sitter {
}
}
bool should_add_action(size_t state_id, const Symbol &symbol, const ParseAction &action) {
bool should_add_action(ParseStateId state_id, const Symbol &symbol, const ParseAction &action) {
auto current_actions = parse_table.states[state_id].actions;
auto current_action = current_actions.find(symbol);
return (

View file

@ -10,7 +10,7 @@ namespace tree_sitter {
using rules::Symbol;
ParseAction::ParseAction(ParseActionType type,
size_t state_index,
ParseStateId state_index,
Symbol symbol,
size_t consumed_symbol_count,
set<int> precedence_values) :
@ -34,20 +34,20 @@ namespace tree_sitter {
return ParseAction(ParseActionTypeAccept, -1, Symbol(-1), 0, { 0 });
}
ParseAction ParseAction::Shift(size_t state_index, set<int> precedence_values) {
ParseAction ParseAction::Shift(ParseStateId state_index, set<int> precedence_values) {
return ParseAction(ParseActionTypeShift, state_index, Symbol(-1), 0, precedence_values);
}
ParseAction ParseAction::ShiftExtra() {
return ParseAction(ParseActionTypeShiftExtra, -1, Symbol(-1), 0, { 0 });
return ParseAction(ParseActionTypeShiftExtra, 0, Symbol(-1), 0, { 0 });
}
ParseAction ParseAction::ReduceExtra(Symbol symbol) {
return ParseAction(ParseActionTypeReduceExtra, -1, symbol, 0, { 0 });
return ParseAction(ParseActionTypeReduceExtra, 0, symbol, 0, { 0 });
}
ParseAction ParseAction::Reduce(Symbol symbol, size_t consumed_symbol_count, int precedence) {
return ParseAction(ParseActionTypeReduce, -1, symbol, consumed_symbol_count, { precedence });
return ParseAction(ParseActionTypeReduce, 0, symbol, consumed_symbol_count, { precedence });
}
bool ParseAction::operator==(const ParseAction &other) const {

View file

@ -9,6 +9,8 @@
#include "compiler/rules/symbol.h"
namespace tree_sitter {
typedef uint64_t ParseStateId;
typedef enum {
ParseActionTypeError,
ParseActionTypeShift,
@ -20,7 +22,7 @@ namespace tree_sitter {
class ParseAction {
ParseAction(ParseActionType type,
size_t state_index,
ParseStateId state_index,
rules::Symbol symbol,
size_t consumed_symbol_count,
std::set<int> precedence_values);
@ -28,7 +30,7 @@ namespace tree_sitter {
ParseAction();
static ParseAction Accept();
static ParseAction Error();
static ParseAction Shift(size_t state_index, std::set<int> precedence_values);
static ParseAction Shift(ParseStateId state_index, std::set<int> precedence_values);
static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count, int precedence);
static ParseAction ShiftExtra();
static ParseAction ReduceExtra(rules::Symbol symbol);
@ -36,7 +38,7 @@ namespace tree_sitter {
ParseActionType type;
rules::Symbol symbol;
size_t state_index;
ParseStateId state_index;
size_t consumed_symbol_count;
std::set<int> precedence_values;
};
@ -66,13 +68,11 @@ namespace tree_sitter {
LexStateId lex_state_id;
};
typedef uint64_t ParseStateId;
std::ostream& operator<<(std::ostream &stream, const ParseState &state);
class ParseTable {
public:
uint64_t add_state();
ParseStateId add_state();
void add_action(ParseStateId state_id, rules::Symbol symbol, ParseAction action);
std::vector<ParseState> states;