Fix ParseStateId / size_t confusion in parse table
This commit is contained in:
parent
c5c25d30bb
commit
f4287c07d0
3 changed files with 12 additions and 12 deletions
|
|
@ -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_actions = parse_table.states[state_id].actions;
|
||||||
auto current_action = current_actions.find(symbol);
|
auto current_action = current_actions.find(symbol);
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace tree_sitter {
|
||||||
using rules::Symbol;
|
using rules::Symbol;
|
||||||
|
|
||||||
ParseAction::ParseAction(ParseActionType type,
|
ParseAction::ParseAction(ParseActionType type,
|
||||||
size_t state_index,
|
ParseStateId state_index,
|
||||||
Symbol symbol,
|
Symbol symbol,
|
||||||
size_t consumed_symbol_count,
|
size_t consumed_symbol_count,
|
||||||
set<int> precedence_values) :
|
set<int> precedence_values) :
|
||||||
|
|
@ -34,20 +34,20 @@ namespace tree_sitter {
|
||||||
return ParseAction(ParseActionTypeAccept, -1, Symbol(-1), 0, { 0 });
|
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);
|
return ParseAction(ParseActionTypeShift, state_index, Symbol(-1), 0, precedence_values);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseAction ParseAction::ShiftExtra() {
|
ParseAction ParseAction::ShiftExtra() {
|
||||||
return ParseAction(ParseActionTypeShiftExtra, -1, Symbol(-1), 0, { 0 });
|
return ParseAction(ParseActionTypeShiftExtra, 0, Symbol(-1), 0, { 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseAction ParseAction::ReduceExtra(Symbol symbol) {
|
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) {
|
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 {
|
bool ParseAction::operator==(const ParseAction &other) const {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@
|
||||||
#include "compiler/rules/symbol.h"
|
#include "compiler/rules/symbol.h"
|
||||||
|
|
||||||
namespace tree_sitter {
|
namespace tree_sitter {
|
||||||
|
typedef uint64_t ParseStateId;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ParseActionTypeError,
|
ParseActionTypeError,
|
||||||
ParseActionTypeShift,
|
ParseActionTypeShift,
|
||||||
|
|
@ -20,7 +22,7 @@ namespace tree_sitter {
|
||||||
|
|
||||||
class ParseAction {
|
class ParseAction {
|
||||||
ParseAction(ParseActionType type,
|
ParseAction(ParseActionType type,
|
||||||
size_t state_index,
|
ParseStateId state_index,
|
||||||
rules::Symbol symbol,
|
rules::Symbol symbol,
|
||||||
size_t consumed_symbol_count,
|
size_t consumed_symbol_count,
|
||||||
std::set<int> precedence_values);
|
std::set<int> precedence_values);
|
||||||
|
|
@ -28,7 +30,7 @@ namespace tree_sitter {
|
||||||
ParseAction();
|
ParseAction();
|
||||||
static ParseAction Accept();
|
static ParseAction Accept();
|
||||||
static ParseAction Error();
|
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 Reduce(rules::Symbol symbol, size_t consumed_symbol_count, int precedence);
|
||||||
static ParseAction ShiftExtra();
|
static ParseAction ShiftExtra();
|
||||||
static ParseAction ReduceExtra(rules::Symbol symbol);
|
static ParseAction ReduceExtra(rules::Symbol symbol);
|
||||||
|
|
@ -36,7 +38,7 @@ namespace tree_sitter {
|
||||||
|
|
||||||
ParseActionType type;
|
ParseActionType type;
|
||||||
rules::Symbol symbol;
|
rules::Symbol symbol;
|
||||||
size_t state_index;
|
ParseStateId state_index;
|
||||||
size_t consumed_symbol_count;
|
size_t consumed_symbol_count;
|
||||||
std::set<int> precedence_values;
|
std::set<int> precedence_values;
|
||||||
};
|
};
|
||||||
|
|
@ -66,13 +68,11 @@ namespace tree_sitter {
|
||||||
LexStateId lex_state_id;
|
LexStateId lex_state_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef uint64_t ParseStateId;
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream &stream, const ParseState &state);
|
std::ostream& operator<<(std::ostream &stream, const ParseState &state);
|
||||||
|
|
||||||
class ParseTable {
|
class ParseTable {
|
||||||
public:
|
public:
|
||||||
uint64_t add_state();
|
ParseStateId add_state();
|
||||||
void add_action(ParseStateId state_id, rules::Symbol symbol, ParseAction action);
|
void add_action(ParseStateId state_id, rules::Symbol symbol, ParseAction action);
|
||||||
|
|
||||||
std::vector<ParseState> states;
|
std::vector<ParseState> states;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue