Remove unused consumed_symbols vector from parse items
This commit is contained in:
parent
d957021982
commit
3f770ff3c3
12 changed files with 203 additions and 220 deletions
|
|
@ -75,7 +75,7 @@ namespace tree_sitter {
|
|||
if (item.is_done()) {
|
||||
ParseAction action = (item.lhs == rules::START) ?
|
||||
ParseAction::Accept() :
|
||||
ParseAction::Reduce(item.lhs, item.consumed_symbols);
|
||||
ParseAction::Reduce(item.lhs, item.consumed_symbol_count);
|
||||
parse_table.add_action(state_id, item.lookahead_sym, action);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace tree_sitter {
|
|||
string(" ") <<
|
||||
*item.rule <<
|
||||
string(" ") <<
|
||||
to_string(item.consumed_symbols.size()) <<
|
||||
to_string(item.consumed_symbol_count) <<
|
||||
string(" ") <<
|
||||
item.lookahead_sym <<
|
||||
string(">");
|
||||
|
|
@ -51,16 +51,16 @@ namespace tree_sitter {
|
|||
|
||||
ParseItem::ParseItem(const Symbol &lhs,
|
||||
const rule_ptr rule,
|
||||
const vector<bool> &consumed_symbols,
|
||||
size_t consumed_symbol_count,
|
||||
const Symbol &lookahead_sym) :
|
||||
Item(lhs, rule),
|
||||
consumed_symbols(consumed_symbols),
|
||||
consumed_symbol_count(consumed_symbol_count),
|
||||
lookahead_sym(lookahead_sym) {}
|
||||
|
||||
bool ParseItem::operator==(const ParseItem &other) const {
|
||||
bool lhs_eq = other.lhs == lhs;
|
||||
bool rules_eq = (*other.rule == *rule);
|
||||
bool consumed_sym_counts_eq = (other.consumed_symbols == consumed_symbols);
|
||||
bool consumed_sym_counts_eq = (other.consumed_symbol_count == consumed_symbol_count);
|
||||
bool lookaheads_eq = other.lookahead_sym == lookahead_sym;
|
||||
return lhs_eq && rules_eq && consumed_sym_counts_eq && lookaheads_eq;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ namespace tree_sitter {
|
|||
public:
|
||||
ParseItem(const rules::Symbol &lhs,
|
||||
const rules::rule_ptr rule,
|
||||
const std::vector<bool> &consumed_symbols,
|
||||
const size_t consumed_symbol_count,
|
||||
const rules::Symbol &lookahead_sym);
|
||||
bool operator==(const ParseItem &other) const;
|
||||
|
||||
const std::vector<bool> consumed_symbols;
|
||||
const size_t consumed_symbol_count;
|
||||
const rules::Symbol lookahead_sym;
|
||||
};
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ namespace std {
|
|||
return
|
||||
hash<string>()(item.lhs.name) ^
|
||||
hash<tree_sitter::rules::rule_ptr>()(item.rule) ^
|
||||
hash<size_t>()(item.consumed_symbols.size()) ^
|
||||
hash<size_t>()(item.consumed_symbol_count) ^
|
||||
hash<string>()(item.lookahead_sym.name);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@ namespace tree_sitter {
|
|||
map<Symbol, ParseItemSet> result;
|
||||
for (auto transition : sym_transitions(item.rule)) {
|
||||
Symbol rule = transition.first;
|
||||
auto consumed_symbols = item.consumed_symbols;
|
||||
consumed_symbols.push_back(rule.is_hidden());
|
||||
ParseItem new_item(item.lhs, transition.second, consumed_symbols, item.lookahead_sym);
|
||||
ParseItem new_item(item.lhs, transition.second, item.consumed_symbol_count + 1, item.lookahead_sym);
|
||||
result.insert({ rule, item_set_closure(ParseItemSet({ new_item }), grammar) });
|
||||
}
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ namespace tree_sitter {
|
|||
case ParseActionTypeReduce:
|
||||
return "REDUCE(" +
|
||||
symbol_id(action.symbol) + ", " +
|
||||
to_string(action.child_flags.size()) + ")";
|
||||
to_string(action.consumed_symbol_count) + ")";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,14 +34,6 @@ namespace tree_sitter {
|
|||
(symbol == other.symbol);
|
||||
}
|
||||
|
||||
bool LexAction::operator<(const LexAction &other) const {
|
||||
if (type < other.type) return true;
|
||||
if (type > other.type) return false;
|
||||
if (state_index < other.state_index) return true;
|
||||
if (state_index > other.state_index) return false;
|
||||
return (symbol < other.symbol);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &stream, const LexAction &action) {
|
||||
switch (action.type) {
|
||||
case LexActionTypeError:
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ namespace tree_sitter {
|
|||
static LexAction Error();
|
||||
static LexAction Advance(size_t state_index);
|
||||
bool operator==(const LexAction &action) const;
|
||||
bool operator<(const LexAction &action) const;
|
||||
|
||||
LexActionType type;
|
||||
rules::Symbol symbol;
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ namespace tree_sitter {
|
|||
ParseAction::ParseAction(ParseActionType type,
|
||||
size_t state_index,
|
||||
Symbol symbol,
|
||||
const vector<bool> &child_flags) :
|
||||
size_t consumed_symbol_count) :
|
||||
type(type),
|
||||
symbol(symbol),
|
||||
state_index(state_index),
|
||||
child_flags(child_flags) {}
|
||||
consumed_symbol_count(consumed_symbol_count) {}
|
||||
|
||||
ParseAction ParseAction::Error() {
|
||||
return ParseAction(ParseActionTypeError, -1, Symbol(""), {});
|
||||
|
|
@ -30,23 +30,15 @@ namespace tree_sitter {
|
|||
return ParseAction(ParseActionTypeShift, state_index, Symbol(""), {});
|
||||
}
|
||||
|
||||
ParseAction ParseAction::Reduce(Symbol symbol, const vector<bool> &child_flags) {
|
||||
return ParseAction(ParseActionTypeReduce, -1, symbol, child_flags);
|
||||
ParseAction ParseAction::Reduce(Symbol symbol, size_t consumed_symbol_count) {
|
||||
return ParseAction(ParseActionTypeReduce, -1, symbol, consumed_symbol_count);
|
||||
}
|
||||
|
||||
bool ParseAction::operator==(const ParseAction &other) const {
|
||||
bool types_eq = type == other.type;
|
||||
bool state_indices_eq = state_index == other.state_index;
|
||||
bool child_flags_eq = child_flags == other.child_flags;
|
||||
return types_eq && state_indices_eq && child_flags_eq;
|
||||
}
|
||||
|
||||
bool ParseAction::operator<(const ParseAction &other) const {
|
||||
if (type < other.type) return true;
|
||||
if (type > other.type) return false;
|
||||
if (state_index < other.state_index) return true;
|
||||
if (state_index > other.state_index) return false;
|
||||
return (child_flags < other.child_flags);
|
||||
bool consumed_symbol_counts_eq = consumed_symbol_count == other.consumed_symbol_count;
|
||||
return types_eq && state_indices_eq && consumed_symbol_counts_eq;
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream &stream, const ParseAction &action) {
|
||||
|
|
|
|||
|
|
@ -20,19 +20,18 @@ namespace tree_sitter {
|
|||
ParseAction(ParseActionType type,
|
||||
size_t state_index,
|
||||
rules::Symbol symbol,
|
||||
const std::vector<bool> &child_flags);
|
||||
size_t consumed_symbol_count);
|
||||
public:
|
||||
static ParseAction Accept();
|
||||
static ParseAction Error();
|
||||
static ParseAction Shift(size_t state_index);
|
||||
static ParseAction Reduce(rules::Symbol symbol, const std::vector<bool> &child_flags);
|
||||
static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count);
|
||||
bool operator==(const ParseAction &action) const;
|
||||
bool operator<(const ParseAction &action) const;
|
||||
|
||||
ParseActionType type;
|
||||
rules::Symbol symbol;
|
||||
size_t state_index;
|
||||
std::vector<bool> child_flags;
|
||||
size_t consumed_symbol_count;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream &stream, const ParseAction &item);
|
||||
|
|
@ -46,7 +45,7 @@ namespace std {
|
|||
hash<int>()(action.type) ^
|
||||
hash<tree_sitter::rules::Symbol>()(action.symbol) ^
|
||||
hash<size_t>()(action.state_index) ^
|
||||
hash<size_t>()(action.child_flags.size()));
|
||||
hash<size_t>()(action.consumed_symbol_count));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue