diff --git a/spec/compiler/build_tables/merge_transitions_spec.cc b/spec/compiler/build_tables/merge_transitions_spec.cc index 0e57dc9d..793bb680 100644 --- a/spec/compiler/build_tables/merge_transitions_spec.cc +++ b/spec/compiler/build_tables/merge_transitions_spec.cc @@ -10,7 +10,7 @@ describe("merging character set transitions", []() { typedef map int_map; auto do_merge = [&](int_map *left, const pair &new_pair) { - merge_char_transitions(left, new_pair, [](int *l, const int *r) { + merge_char_transition(left, new_pair, [](int *l, const int *r) { *l = *l | *r; }); }; diff --git a/src/compiler/build_tables/item_set_transitions.cc b/src/compiler/build_tables/item_set_transitions.cc index ef39caa7..e0b80292 100644 --- a/src/compiler/build_tables/item_set_transitions.cc +++ b/src/compiler/build_tables/item_set_transitions.cc @@ -21,7 +21,7 @@ namespace tree_sitter { const set &lookahead_symbols = pair.second; for (auto &transition : sym_transitions(item.rule)) { ParseItem new_item(item.lhs, transition.second, item.consumed_symbol_count + 1); - merge_sym_transitions(&result, { transition.first, item_set_closure(new_item, lookahead_symbols, grammar) }, + merge_sym_transition(&result, { transition.first, item_set_closure(new_item, lookahead_symbols, grammar) }, [](ParseItemSet *left, const ParseItemSet *right) { for (auto &pair : *right) left->operator[](pair.first).insert(pair.second.begin(), pair.second.end()); @@ -37,7 +37,7 @@ namespace tree_sitter { for (const LexItem &item : item_set) { for (auto &transition : char_transitions(item.rule)) { LexItem next_item(item.lhs, transition.second); - merge_char_transitions(&result, { transition.first, LexItemSet({ next_item }) }, + merge_char_transition(&result, { transition.first, LexItemSet({ next_item }) }, [](LexItemSet *left, const LexItemSet *right) { left->insert(right->begin(), right->end()); }); diff --git a/src/compiler/build_tables/merge_transitions.h b/src/compiler/build_tables/merge_transitions.h index 1a28cee8..52ab8d15 100644 --- a/src/compiler/build_tables/merge_transitions.h +++ b/src/compiler/build_tables/merge_transitions.h @@ -9,15 +9,15 @@ namespace tree_sitter { namespace build_tables { /* - * Merges two transition maps with symbol keys. If both maps - * contain values for the same symbol, the new value for that - * symbol will be computed by merging the two previous values + * Merges a new transition into a map with symbol keys. + * If the symbol already exists in the map, the new value for that + * symbol will be computed by merging the old and new values * using the given function. */ template - void merge_sym_transitions(std::map *left, - const std::pair &new_pair, - std::function merge_fn) { + void merge_sym_transition(std::map *left, + const std::pair &new_pair, + std::function merge_fn) { auto new_symbol = new_pair.first; for (auto &existing_pair : *left) { auto existing_symbol = existing_pair.first; @@ -34,12 +34,12 @@ namespace tree_sitter { * Merges two transition maps with character set keys. If the * two maps contain values for overlapping character sets, the * new value for the two sets' intersection will be computed by - * merging the two previous values using the given function. + * merging the old and new values using the given function. */ template - void merge_char_transitions(std::map *left, - const std::pair &new_pair, - std::function merge_fn) { + void merge_char_transition(std::map *left, + const std::pair &new_pair, + std::function merge_fn) { rules::CharacterSet new_char_set = new_pair.first; T new_value = new_pair.second; diff --git a/src/compiler/build_tables/rule_transitions.cc b/src/compiler/build_tables/rule_transitions.cc index 2d318aad..8ba6a198 100644 --- a/src/compiler/build_tables/rule_transitions.cc +++ b/src/compiler/build_tables/rule_transitions.cc @@ -26,7 +26,7 @@ namespace tree_sitter { template<> void merge_transitions(map *left, const map &right) { for (auto &pair : right) - merge_char_transitions(left, pair, [](rule_ptr *left, const rule_ptr *right) { + merge_char_transition(left, pair, [](rule_ptr *left, const rule_ptr *right) { *left = rules::Choice::Build({ *left, *right }); }); } @@ -34,7 +34,7 @@ namespace tree_sitter { template<> void merge_transitions(map *left, const map &right) { for (auto &pair : right) - merge_sym_transitions(left, pair, [](rule_ptr *left, const rule_ptr *right) { + merge_sym_transition(left, pair, [](rule_ptr *left, const rule_ptr *right) { *left = rules::Choice::Build({ *left, *right }); }); }