#include "keyword_comp.h" #include #include "sentinel_runtime_state.h" using namespace std; static const string whitespaces = " \t"; static string getSubStrNoPadding(const string &str, uint start, uint end) { auto r_start = str.find_first_not_of(whitespaces, start); auto r_end = str.find_last_not_of(whitespaces, end-1); if (r_end==string::npos || r_start==string::npos || r_start>r_end) { throw KeywordError("Found an empty section in the '"+ str + "'"); } return str.substr(r_start, r_end-r_start+1); } static vector split(const string &str, const string &delim, uint start = 0) { vector res; uint part_start = start; bool escape = false; bool in_string = false; for (uint index = start; index::From { public: Maybe> genRule(const string &rule) { shared_ptr res; try { res = KeywordsRuleImpl::genRule(rule); } catch (const KeywordError &e) { return genError(e.getErr());; } return move(res); } private: class KeywordsRuleImpl : public VirtualRule { public: bool isMatch() const override { return start.isMatch() == MatchStatus::Match; } static unique_ptr genRule(const string &rule) { auto res = make_unique(); auto pos = rule.find_last_not_of(whitespaces); if (pos==string::npos) { // Empty rule return res; } if (rule[pos]!=';') throw KeywordError(rule + " - end of text pass rule"); VariablesMapping known_vars; auto key_vec = split(rule, ";"); for (auto &keyword : key_vec) { res->start.appendKeyword(getKeywordByName(keyword, known_vars)); } return res; } private: SentinelKeyword start; }; }; KeywordComp::KeywordComp() : Component("KeywordComp"), pimpl(make_unique()) {} KeywordComp::~KeywordComp() {} string I_KeywordsRule::keywords_tag = "keywords_rule_tag";