| 58 | } |
| 59 | |
| 60 | method_base *match(const std::deque<token_base *> &raw) |
| 61 | { |
| 62 | if (raw.size() <= 1) |
| 63 | throw compile_error("Empty input when matching grammar."); |
| 64 | std::list<std::shared_ptr<data_type>> stack; |
| 65 | for (auto &it : m_data) |
| 66 | if (cs::translator_type::compare(it->first.front(), raw.front())) |
| 67 | stack.push_back(it); |
| 68 | stack.remove_if([&](const std::shared_ptr<data_type> &dat) { |
| 69 | return dat->first.size() != raw.size(); |
| 70 | }); |
| 71 | stack.remove_if([&](const std::shared_ptr<data_type> &dat) { |
| 72 | for (std::size_t i = 1; i < raw.size() - 1; ++i) { |
| 73 | if (!compare(raw.at(i), dat->first.at(i))) |
| 74 | return true; |
| 75 | } |
| 76 | return false; |
| 77 | }); |
| 78 | if (stack.empty()) |
| 79 | throw compile_error("Unknown grammar."); |
| 80 | if (stack.size() > 1) |
| 81 | throw compile_error("Ambiguous grammar."); |
| 82 | return stack.front()->second; |
| 83 | } |
| 84 | |
| 85 | void match_grammar(const context_t &, std::deque<token_base *> &); |
| 86 |
no test coverage detected