Store parse actions' precedences as ranges, not sets
This commit is contained in:
parent
ef2acf9496
commit
6d748a6714
8 changed files with 105 additions and 50 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "compiler/parse_table.h"
|
||||
#include "compiler/precedence_range.h"
|
||||
#include <string>
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
@ -12,13 +13,13 @@ using rules::Symbol;
|
|||
|
||||
ParseAction::ParseAction(ParseActionType type, ParseStateId state_index,
|
||||
Symbol symbol, size_t consumed_symbol_count,
|
||||
set<int> precedence_values,
|
||||
PrecedenceRange precedence_range,
|
||||
Associativity associativity, int production_id)
|
||||
: type(type),
|
||||
symbol(symbol),
|
||||
state_index(state_index),
|
||||
consumed_symbol_count(consumed_symbol_count),
|
||||
precedence_values(precedence_values),
|
||||
precedence_range(precedence_range),
|
||||
associativity(associativity),
|
||||
production_id(production_id) {}
|
||||
|
||||
|
|
@ -40,9 +41,9 @@ ParseAction ParseAction::Accept() {
|
|||
}
|
||||
|
||||
ParseAction ParseAction::Shift(ParseStateId state_index,
|
||||
set<int> precedence_values) {
|
||||
PrecedenceRange precedence_range) {
|
||||
return ParseAction(ParseActionTypeShift, state_index, Symbol(-1), 0,
|
||||
precedence_values, AssociativityNone, -1);
|
||||
precedence_range, AssociativityNone, -1);
|
||||
}
|
||||
|
||||
ParseAction ParseAction::ShiftExtra() {
|
||||
|
|
@ -62,7 +63,7 @@ ParseAction ParseAction::Reduce(Symbol symbol, size_t consumed_symbol_count,
|
|||
int precedence, Associativity associativity,
|
||||
unsigned int production_id) {
|
||||
return ParseAction(ParseActionTypeReduce, 0, symbol, consumed_symbol_count,
|
||||
{ precedence }, associativity, production_id);
|
||||
{ precedence, precedence }, associativity, production_id);
|
||||
}
|
||||
|
||||
bool ParseAction::operator==(const ParseAction &other) const {
|
||||
|
|
@ -71,7 +72,9 @@ bool ParseAction::operator==(const ParseAction &other) const {
|
|||
bool state_indices_eq = state_index == other.state_index;
|
||||
bool consumed_symbol_counts_eq =
|
||||
consumed_symbol_count == other.consumed_symbol_count;
|
||||
return types_eq && symbols_eq && state_indices_eq && consumed_symbol_counts_eq;
|
||||
bool precedences_eq = precedence_range == other.precedence_range;
|
||||
return types_eq && symbols_eq && state_indices_eq &&
|
||||
consumed_symbol_counts_eq && precedences_eq;
|
||||
}
|
||||
|
||||
bool ParseAction::operator<(const ParseAction &other) const {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue