@@ -13,7 +13,7 @@ grammar::Productions RemoveLeftFactors(const grammar::Production &prod) {
1313 bool state_not_updated = false ;
1414 auto current_prod = prod;
1515 while (!state_not_updated) {
16- auto max_common_prefix = utils::LongestCommonPrefix (current_prod);
16+ auto max_common_prefix = utils::LongestCommonPrefix (current_prod). GetEntities () ;
1717 if (max_common_prefix.empty ()) {
1818 state_not_updated = true ;
1919 continue ;
@@ -26,29 +26,31 @@ grammar::Productions RemoveLeftFactors(const grammar::Production &prod) {
2626 grammar::Rules parent_dash_rules;
2727
2828 // insert the commonE' prod
29- grammar::Entity common_factor_with_dash (max_common_prefix.begin (), max_common_prefix.end ());
29+ std::vector<std::string> common_factor_with_dash (max_common_prefix.begin (), max_common_prefix.end ());
3030 // push E' after the common part
3131 common_factor_with_dash.emplace_back (parent_dash);
3232 parent_rules.emplace_back (grammar::Rule (common_factor_with_dash));
3333
3434 bool has_epsilon_inserted = false ;
3535 // produce two production after matching
3636 for (const auto &rule : current_prod.GetRules ()) {
37- if (!rule.HasPrefix (max_common_prefix)) {
37+ if (!rule.HasPrefix (grammar::Rule ( max_common_prefix) )) {
3838 parent_rules.emplace_back (rule);
3939 } else {
40- auto new_entities = grammar::Entity (rule. GetEntities (). begin () + static_cast < int >(max_common_prefix. size ()),
41- rule.GetEntities ().end ());
40+ auto new_entities = std::vector<std::string>(
41+ rule. GetEntities (). begin () + static_cast < int >(max_common_prefix. size ()), rule.GetEntities ().end ());
4242 if (new_entities.empty ()) {
4343 has_epsilon_inserted = true ;
4444 new_entities.emplace_back (std::string (grammar::EPSILON));
4545 }
46- parent_dash_rules.push_back ( grammar::Rule ( new_entities) );
46+ parent_dash_rules.emplace_back ( new_entities);
4747 }
4848 }
49+
4950 if (!has_epsilon_inserted) {
50- parent_dash_rules.emplace_back (grammar::Entity {std::string (grammar::EPSILON)});
51+ parent_dash_rules.emplace_back (std::vector<std::string> {std::string (grammar::EPSILON)});
5152 }
53+
5254 // do this recursive
5355 prods.push_back (grammar::Production (parent, parent_rules));
5456 current_prod = grammar::Production (parent_dash, parent_dash_rules);
@@ -57,10 +59,11 @@ grammar::Productions RemoveLeftFactors(const grammar::Production &prod) {
5759 return prods;
5860}
5961
60- grammar::Entity LongestCommonPrefix (const grammar::Production &prod) {
62+ grammar::Rule LongestCommonPrefix (const grammar::Production &prod) {
6163 TrieManager trie_manager;
6264 trie_manager.InsertAll (prod);
63- grammar::Entity common_prefixes;
65+
66+ grammar::Rule common_prefixes;
6467 int len = 1 ;
6568 TrieManager::GreedyPreorder (trie_manager.GetMaster (), len, common_prefixes, true );
6669
0 commit comments