update
This commit is contained in:
parent
ec56d7e63b
commit
bc5ccb37e8
|
@ -19,6 +19,7 @@ QList<std::shared_ptr<const MatchCursor>> __anyone_impl::parse(std::shared_ptr<c
|
|||
if (cursor->mustStop())
|
||||
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
||||
|
||||
auto syntax = present();
|
||||
QList<std::shared_ptr<const MatchCursor>> result_list;
|
||||
for (auto rx : this->children())
|
||||
result_list.append(rx->parse(cursor));
|
||||
|
@ -58,39 +59,41 @@ QList<std::shared_ptr<const MatchCursor>> __sequence_impl::parse(std::shared_ptr
|
|||
if (cursor->mustStop())
|
||||
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
||||
|
||||
QList<std::shared_ptr<const MatchCursor>> results;
|
||||
QList<std::shared_ptr<const MatchCursor>> bridge_list{ cursor };
|
||||
for (auto rule : this->children()) {
|
||||
QList<std::shared_ptr<const MatchCursor>> current_result;
|
||||
std::for_each(bridge_list.begin(), bridge_list.end(),
|
||||
[&](std::shared_ptr<const MatchCursor> vcurs) {
|
||||
for (auto vcurs : bridge_list) {
|
||||
if (!vcurs->mustStop()) {
|
||||
current_result.append(rule->parse(vcurs));
|
||||
}
|
||||
else {
|
||||
results.push_back(vcurs);
|
||||
}
|
||||
|
||||
// 完全匹配的分支
|
||||
decltype(current_result) temprary_list;
|
||||
std::copy_if(current_result.begin(), current_result.end(),
|
||||
std::back_inserter(temprary_list), [&](std::shared_ptr<const MatchCursor> ins) {
|
||||
return cursor->totalErrorCount() == ins->totalErrorCount();
|
||||
});
|
||||
if (temprary_list.size()) {
|
||||
bridge_list = temprary_list;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// 经过修复的分支
|
||||
std::copy_if(current_result.begin(), current_result.end(), std::back_inserter(temprary_list),
|
||||
[&](std::shared_ptr<const MatchCursor> ins) { return !ins->mustStop(); });
|
||||
if (temprary_list.size()) {
|
||||
bridge_list = temprary_list;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
bridge_list = current_result;
|
||||
break;
|
||||
}
|
||||
|
||||
// 完全匹配分支集合
|
||||
decltype(bridge_list) completely_list;
|
||||
std::copy_if(bridge_list.begin(), bridge_list.end(), std::back_inserter(completely_list),
|
||||
[&](std::shared_ptr<const MatchCursor> ins) { return ins->totalErrorCount() == cursor->totalErrorCount(); });
|
||||
if (completely_list.size())
|
||||
return completely_list;
|
||||
|
||||
// 经过修正的分支
|
||||
decltype(bridge_list) modify_list;
|
||||
std::copy_if(bridge_list.begin(), bridge_list.end(), std::back_inserter(modify_list),
|
||||
[](std::shared_ptr<const MatchCursor> ins) { return !ins->mustStop(); });
|
||||
if (modify_list.size())
|
||||
return modify_list;
|
||||
|
||||
results.append(bridge_list);
|
||||
return results;
|
||||
return bridge_list;
|
||||
}
|
||||
|
||||
QString __sequence_impl::present() const {
|
||||
|
@ -112,6 +115,8 @@ QList<std::shared_ptr<const MatchCursor>> __repeat_impl::parse(std::shared_ptr<c
|
|||
if (cursor->mustStop())
|
||||
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
||||
|
||||
auto syntax = present();
|
||||
|
||||
QList<std::shared_ptr<const MatchCursor>> max_match_begin = { cursor };
|
||||
if (min_match) {
|
||||
QList<std::shared_ptr<const IBasicRule>> temp_rules;
|
||||
|
@ -135,31 +140,41 @@ QList<std::shared_ptr<const MatchCursor>> __repeat_impl::parse(std::shared_ptr<c
|
|||
max_match_begin.removeAt(idx--);
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<const MatchCursor>> results = max_match_begin;
|
||||
QList<std::shared_ptr<const MatchCursor>> results;
|
||||
decltype(results) bridge_list = max_match_begin;
|
||||
// 尝试重复匹配最大次数
|
||||
for (auto idx = min_match; idx < max_match && bridge_list.size(); ++idx) {
|
||||
for (auto idx = min_match; idx < max_match; ++idx) {
|
||||
QList<std::shared_ptr<const MatchCursor>> current_list;
|
||||
|
||||
// 匹配迭代一次
|
||||
std::for_each(bridge_list.begin(), bridge_list.end(),
|
||||
[&](std::shared_ptr<const MatchCursor> ins) {
|
||||
for (auto ins : bridge_list)
|
||||
current_list.append(this->rule_peer->parse(ins));
|
||||
|
||||
// 提取完全匹配的分支
|
||||
QList<std::shared_ptr<const MatchCursor>> temprary_branchs;
|
||||
std::copy_if(current_list.begin(), current_list.end(),
|
||||
std::back_inserter(temprary_branchs), [&](std::shared_ptr<const MatchCursor> ins) {
|
||||
return cursor->totalErrorCount() == ins->totalErrorCount() &&
|
||||
ins->currentToken()->position() > cursor->currentToken()->position();
|
||||
});
|
||||
|
||||
for (auto vdx = 0; vdx < current_list.size(); ++vdx) {
|
||||
auto rst_branch = current_list.at(vdx);
|
||||
if (rst_branch->mustStop()) {
|
||||
results.append(rst_branch);
|
||||
current_list.removeAt(vdx--);
|
||||
}
|
||||
if (temprary_branchs.size()) {
|
||||
bridge_list = temprary_branchs;
|
||||
continue;
|
||||
}
|
||||
|
||||
bridge_list = current_list;
|
||||
// 提取语法修正分支
|
||||
std::copy_if(current_list.begin(), current_list.end(),
|
||||
std::back_inserter(temprary_branchs), [&](std::shared_ptr<const MatchCursor> ins) {
|
||||
return !ins->mustStop() && ins->currentToken()->position() > cursor->currentToken()->position();
|
||||
});
|
||||
if (temprary_branchs.size()) {
|
||||
bridge_list = temprary_branchs;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
results.append(bridge_list);
|
||||
|
||||
|
||||
std::sort(results.begin(), results.end(),
|
||||
[](std::shared_ptr<const MatchCursor> a, std::shared_ptr<const MatchCursor> b) {
|
||||
return a->currentToken()->position() > b->currentToken()->position();
|
||||
|
@ -167,8 +182,7 @@ QList<std::shared_ptr<const MatchCursor>> __repeat_impl::parse(std::shared_ptr<c
|
|||
|
||||
// 提取完全匹配的分支
|
||||
decltype(results) rets_completely;
|
||||
std::for_each(results.begin(), results.end(),
|
||||
[&](std::shared_ptr<const MatchCursor> ins) {
|
||||
for (auto ins : results) {
|
||||
if (ins->totalErrorCount() == cursor->totalErrorCount()) {
|
||||
if (!rets_completely.size()) {
|
||||
rets_completely.append(ins);
|
||||
|
@ -177,12 +191,11 @@ QList<std::shared_ptr<const MatchCursor>> __repeat_impl::parse(std::shared_ptr<c
|
|||
rets_completely.append(ins);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 提取经过修正的分支
|
||||
decltype(results) rets_modified;
|
||||
std::for_each(results.begin(), results.end(),
|
||||
[&](std::shared_ptr<const MatchCursor> ins) {
|
||||
for (auto ins : results) {
|
||||
if (!ins->mustStop()) {
|
||||
if (!rets_modified.size()) {
|
||||
rets_modified.append(ins);
|
||||
|
@ -191,7 +204,7 @@ QList<std::shared_ptr<const MatchCursor>> __repeat_impl::parse(std::shared_ptr<c
|
|||
rets_modified.append(ins);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 允许持续的集合
|
||||
rets_completely.append(rets_modified);
|
||||
|
@ -238,9 +251,12 @@ MatchCursor::MatchCursor(std::shared_ptr<const MatchCursor> other_ptr)
|
|||
: _prev_cursor(other_ptr),
|
||||
_file_path(other_ptr->_file_path),
|
||||
_total_errors(other_ptr->_total_errors),
|
||||
_exprs_errors(other_ptr->_exprs_errors),
|
||||
_current_token(other_ptr->_current_token),
|
||||
_remains_word(other_ptr->_remains_word) { }
|
||||
_remains_word(other_ptr->_remains_word) {
|
||||
for (auto err_pack : other_ptr->_exprs_errors) {
|
||||
_exprs_errors << std::make_shared<ErrsPack>(*err_pack);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<const MatchCursor> MatchCursor::previous() const {
|
||||
return _prev_cursor;
|
||||
|
@ -299,6 +315,11 @@ bool lib_syntax::MatchCursor::parse_stop() const {
|
|||
return !currentWords();
|
||||
}
|
||||
|
||||
lib_syntax::MatchCursor::ErrsPack::ErrsPack() { }
|
||||
|
||||
lib_syntax::MatchCursor::ErrsPack::ErrsPack(const ErrsPack& other)
|
||||
: _error_collection(other._error_collection) { }
|
||||
|
||||
void MatchCursor::ErrsPack::addError(const QString& msg) {
|
||||
this->_error_collection.append(msg);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,9 @@ namespace lib_syntax {
|
|||
public:
|
||||
class ErrsPack {
|
||||
public:
|
||||
ErrsPack();
|
||||
ErrsPack(const ErrsPack& other);
|
||||
|
||||
void addError(const QString& msg);
|
||||
QList<QString> errors() const;
|
||||
uint64_t errorCount() const;
|
||||
|
@ -292,6 +295,8 @@ namespace lib_syntax {
|
|||
if (cursor->mustStop())
|
||||
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
||||
|
||||
auto syntax = present();
|
||||
|
||||
auto t_this = cursor->currentToken();
|
||||
auto w_this = cursor->currentWords();
|
||||
// 起始Token打点
|
||||
|
@ -324,8 +329,7 @@ namespace lib_syntax {
|
|||
|
||||
|
||||
decltype(nbranch) results_fnl;
|
||||
std::for_each(branch_procs.begin(), branch_procs.end(),
|
||||
[&](std::shared_ptr<const MatchCursor> curs) {
|
||||
for (auto curs : branch_procs) {
|
||||
if (curs->mustStop())
|
||||
results_fnl.append(curs);
|
||||
else {
|
||||
|
@ -339,7 +343,7 @@ namespace lib_syntax {
|
|||
ecursor->setCurrent(split_end, w_end);
|
||||
results_fnl.append(ecursor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return results_fnl;
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
auto syntax_text = this->present();
|
||||
auto current_rst = content_extract(cursor->currentToken());
|
||||
auto rst = _children_store->parse(cursor);
|
||||
|
||||
return rst;
|
||||
}
|
||||
};
|
||||
|
@ -129,7 +130,16 @@ public:
|
|||
|
||||
// 通过 ElementRule 继承
|
||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
||||
return _children_store->parse(cursor);
|
||||
auto syntax = this->present();
|
||||
auto current_rst = content_extract(cursor->currentToken());
|
||||
auto rst = _children_store->parse(cursor);
|
||||
|
||||
QString result_list;
|
||||
for (auto c : rst) {
|
||||
result_list += content_extract(c->currentToken()) += "\n";
|
||||
}
|
||||
|
||||
return rst;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue