MCPcopy Create free account
hub / github.com/covscript/covscript / match

Method match

include/covscript/impl/compiler.hpp:60–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

translateMethod · 0.95
get_signal_levelMethod · 0.45
match_methodMethod · 0.45

Calls 4

compile_errorClass · 0.85
sizeMethod · 0.80
compareFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected