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())
|
if (cursor->mustStop())
|
||||||
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
||||||
|
|
||||||
|
auto syntax = present();
|
||||||
QList<std::shared_ptr<const MatchCursor>> result_list;
|
QList<std::shared_ptr<const MatchCursor>> result_list;
|
||||||
for (auto rx : this->children())
|
for (auto rx : this->children())
|
||||||
result_list.append(rx->parse(cursor));
|
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())
|
if (cursor->mustStop())
|
||||||
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
||||||
|
|
||||||
QList<std::shared_ptr<const MatchCursor>> results;
|
|
||||||
QList<std::shared_ptr<const MatchCursor>> bridge_list{ cursor };
|
QList<std::shared_ptr<const MatchCursor>> bridge_list{ cursor };
|
||||||
for (auto rule : this->children()) {
|
for (auto rule : this->children()) {
|
||||||
QList<std::shared_ptr<const MatchCursor>> current_result;
|
QList<std::shared_ptr<const MatchCursor>> current_result;
|
||||||
std::for_each(bridge_list.begin(), bridge_list.end(),
|
for (auto vcurs : bridge_list) {
|
||||||
[&](std::shared_ptr<const MatchCursor> vcurs) {
|
if (!vcurs->mustStop()) {
|
||||||
if (!vcurs->mustStop()) {
|
current_result.append(rule->parse(vcurs));
|
||||||
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;
|
bridge_list = current_result;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 完全匹配分支集合
|
return bridge_list;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString __sequence_impl::present() const {
|
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())
|
if (cursor->mustStop())
|
||||||
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
||||||
|
|
||||||
|
auto syntax = present();
|
||||||
|
|
||||||
QList<std::shared_ptr<const MatchCursor>> max_match_begin = { cursor };
|
QList<std::shared_ptr<const MatchCursor>> max_match_begin = { cursor };
|
||||||
if (min_match) {
|
if (min_match) {
|
||||||
QList<std::shared_ptr<const IBasicRule>> temp_rules;
|
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--);
|
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;
|
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;
|
QList<std::shared_ptr<const MatchCursor>> current_list;
|
||||||
|
|
||||||
// 匹配迭代一次
|
// 匹配迭代一次
|
||||||
std::for_each(bridge_list.begin(), bridge_list.end(),
|
for (auto ins : bridge_list)
|
||||||
[&](std::shared_ptr<const MatchCursor> ins) {
|
current_list.append(this->rule_peer->parse(ins));
|
||||||
current_list.append(this->rule_peer->parse(ins));
|
|
||||||
});
|
|
||||||
|
|
||||||
for (auto vdx = 0; vdx < current_list.size(); ++vdx) {
|
// 提取完全匹配的分支
|
||||||
auto rst_branch = current_list.at(vdx);
|
QList<std::shared_ptr<const MatchCursor>> temprary_branchs;
|
||||||
if (rst_branch->mustStop()) {
|
std::copy_if(current_list.begin(), current_list.end(),
|
||||||
results.append(rst_branch);
|
std::back_inserter(temprary_branchs), [&](std::shared_ptr<const MatchCursor> ins) {
|
||||||
current_list.removeAt(vdx--);
|
return cursor->totalErrorCount() == ins->totalErrorCount() &&
|
||||||
}
|
ins->currentToken()->position() > cursor->currentToken()->position();
|
||||||
|
});
|
||||||
|
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);
|
results.append(bridge_list);
|
||||||
|
|
||||||
|
|
||||||
std::sort(results.begin(), results.end(),
|
std::sort(results.begin(), results.end(),
|
||||||
[](std::shared_ptr<const MatchCursor> a, std::shared_ptr<const MatchCursor> b) {
|
[](std::shared_ptr<const MatchCursor> a, std::shared_ptr<const MatchCursor> b) {
|
||||||
return a->currentToken()->position() > b->currentToken()->position();
|
return a->currentToken()->position() > b->currentToken()->position();
|
||||||
|
@ -167,31 +182,29 @@ QList<std::shared_ptr<const MatchCursor>> __repeat_impl::parse(std::shared_ptr<c
|
||||||
|
|
||||||
// 提取完全匹配的分支
|
// 提取完全匹配的分支
|
||||||
decltype(results) rets_completely;
|
decltype(results) rets_completely;
|
||||||
std::for_each(results.begin(), results.end(),
|
for (auto ins : results) {
|
||||||
[&](std::shared_ptr<const MatchCursor> ins) {
|
if (ins->totalErrorCount() == cursor->totalErrorCount()) {
|
||||||
if (ins->totalErrorCount() == cursor->totalErrorCount()) {
|
if (!rets_completely.size()) {
|
||||||
if (!rets_completely.size()) {
|
rets_completely.append(ins);
|
||||||
rets_completely.append(ins);
|
|
||||||
}
|
|
||||||
else if (rets_completely.last()->currentToken()->position() == ins->currentToken()->position()) {
|
|
||||||
rets_completely.append(ins);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
else if (rets_completely.last()->currentToken()->position() == ins->currentToken()->position()) {
|
||||||
|
rets_completely.append(ins);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 提取经过修正的分支
|
// 提取经过修正的分支
|
||||||
decltype(results) rets_modified;
|
decltype(results) rets_modified;
|
||||||
std::for_each(results.begin(), results.end(),
|
for (auto ins : results) {
|
||||||
[&](std::shared_ptr<const MatchCursor> ins) {
|
if (!ins->mustStop()) {
|
||||||
if (!ins->mustStop()) {
|
if (!rets_modified.size()) {
|
||||||
if (!rets_modified.size()) {
|
rets_modified.append(ins);
|
||||||
rets_modified.append(ins);
|
|
||||||
}
|
|
||||||
else if (rets_modified.last()->currentToken()->position() == ins->currentToken()->position()) {
|
|
||||||
rets_modified.append(ins);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
else if (rets_modified.last()->currentToken()->position() == ins->currentToken()->position()) {
|
||||||
|
rets_modified.append(ins);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 允许持续的集合
|
// 允许持续的集合
|
||||||
rets_completely.append(rets_modified);
|
rets_completely.append(rets_modified);
|
||||||
|
@ -238,9 +251,12 @@ MatchCursor::MatchCursor(std::shared_ptr<const MatchCursor> other_ptr)
|
||||||
: _prev_cursor(other_ptr),
|
: _prev_cursor(other_ptr),
|
||||||
_file_path(other_ptr->_file_path),
|
_file_path(other_ptr->_file_path),
|
||||||
_total_errors(other_ptr->_total_errors),
|
_total_errors(other_ptr->_total_errors),
|
||||||
_exprs_errors(other_ptr->_exprs_errors),
|
|
||||||
_current_token(other_ptr->_current_token),
|
_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 {
|
std::shared_ptr<const MatchCursor> MatchCursor::previous() const {
|
||||||
return _prev_cursor;
|
return _prev_cursor;
|
||||||
|
@ -299,6 +315,11 @@ bool lib_syntax::MatchCursor::parse_stop() const {
|
||||||
return !currentWords();
|
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) {
|
void MatchCursor::ErrsPack::addError(const QString& msg) {
|
||||||
this->_error_collection.append(msg);
|
this->_error_collection.append(msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,9 @@ namespace lib_syntax {
|
||||||
public:
|
public:
|
||||||
class ErrsPack {
|
class ErrsPack {
|
||||||
public:
|
public:
|
||||||
|
ErrsPack();
|
||||||
|
ErrsPack(const ErrsPack& other);
|
||||||
|
|
||||||
void addError(const QString& msg);
|
void addError(const QString& msg);
|
||||||
QList<QString> errors() const;
|
QList<QString> errors() const;
|
||||||
uint64_t errorCount() const;
|
uint64_t errorCount() const;
|
||||||
|
@ -292,6 +295,8 @@ namespace lib_syntax {
|
||||||
if (cursor->mustStop())
|
if (cursor->mustStop())
|
||||||
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
return QList<std::shared_ptr<const MatchCursor>>() << cursor;
|
||||||
|
|
||||||
|
auto syntax = present();
|
||||||
|
|
||||||
auto t_this = cursor->currentToken();
|
auto t_this = cursor->currentToken();
|
||||||
auto w_this = cursor->currentWords();
|
auto w_this = cursor->currentWords();
|
||||||
// 起始Token打点
|
// 起始Token打点
|
||||||
|
@ -324,22 +329,21 @@ namespace lib_syntax {
|
||||||
|
|
||||||
|
|
||||||
decltype(nbranch) results_fnl;
|
decltype(nbranch) results_fnl;
|
||||||
std::for_each(branch_procs.begin(), branch_procs.end(),
|
for (auto curs : branch_procs) {
|
||||||
[&](std::shared_ptr<const MatchCursor> curs) {
|
if (curs->mustStop())
|
||||||
if (curs->mustStop())
|
results_fnl.append(curs);
|
||||||
results_fnl.append(curs);
|
else {
|
||||||
else {
|
auto t_end = curs->currentToken();
|
||||||
auto t_end = curs->currentToken();
|
auto w_end = curs->currentWords();
|
||||||
auto w_end = curs->currentWords();
|
|
||||||
|
|
||||||
auto ecursor = std::make_shared<MatchCursor>(curs);
|
auto ecursor = std::make_shared<MatchCursor>(curs);
|
||||||
ecursor->quitExprs();
|
ecursor->quitExprs();
|
||||||
|
|
||||||
auto split_end = std::make_shared<lib_token::ExprEndToken<ExprType>>(split_begin, t_end);
|
auto split_end = std::make_shared<lib_token::ExprEndToken<ExprType>>(split_begin, t_end);
|
||||||
ecursor->setCurrent(split_end, w_end);
|
ecursor->setCurrent(split_end, w_end);
|
||||||
results_fnl.append(ecursor);
|
results_fnl.append(ecursor);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return results_fnl;
|
return results_fnl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ public:
|
||||||
auto syntax_text = this->present();
|
auto syntax_text = this->present();
|
||||||
auto current_rst = content_extract(cursor->currentToken());
|
auto current_rst = content_extract(cursor->currentToken());
|
||||||
auto rst = _children_store->parse(cursor);
|
auto rst = _children_store->parse(cursor);
|
||||||
|
|
||||||
return rst;
|
return rst;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -129,7 +130,16 @@ public:
|
||||||
|
|
||||||
// 通过 ElementRule 继承
|
// 通过 ElementRule 继承
|
||||||
QList<std::shared_ptr<const MatchCursor>> expr_rule_parse(std::shared_ptr<const MatchCursor> cursor) const override {
|
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