update
This commit is contained in:
parent
ee94744b6a
commit
150ab3b354
|
@ -74,6 +74,7 @@
|
|||
</Link>
|
||||
<ClCompile>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<PreprocessToFile>false</PreprocessToFile>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
|
|
@ -34,6 +34,31 @@ QString Any::present() const {
|
|||
return members_content.mid(0, members_content.size() - 1);
|
||||
}
|
||||
|
||||
QList<QString> lib_syntax::Any::invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const {
|
||||
QList<QString> lines;
|
||||
|
||||
lines << QString(u8"if (%1->mustStop())").arg(in_cursor_name);
|
||||
lines << QString(u8" return QList<std::shared_ptr<const MatchCursor>>() << %1; ").arg(in_cursor_name);
|
||||
|
||||
lines << QString(u8"QList<std::shared_ptr<const MatchCursor>> result_list_%1;").arg((uint64_t) this);
|
||||
for (auto rule : children()) {
|
||||
auto segments = rule->invokeSegments(in_cursor_name, QString(u8"result_list_%1").arg((uint64_t) this));
|
||||
if (segments.size() == 1) {
|
||||
lines.append(segments);
|
||||
}
|
||||
else {
|
||||
lines << u8"{";
|
||||
lines.append(segments);
|
||||
lines << u8"}";
|
||||
}
|
||||
}
|
||||
lines << QString(u8"%2 = result_list_%1;").arg((uint64_t) this).arg(out_list_name);
|
||||
}
|
||||
|
||||
QString lib_syntax::Any::implementSegments(const QString& in_cursor_name, QList<QString>& lines) const {
|
||||
return QString();
|
||||
}
|
||||
|
||||
Seqs::Seqs(const QList<std::shared_ptr<const IBasicRule>> mbrs) : mbrs_store(mbrs) { }
|
||||
|
||||
QList<std::shared_ptr<const IBasicRule>> Seqs::children() const {
|
||||
|
@ -71,6 +96,28 @@ QString Seqs::present() const {
|
|||
return content.mid(0, content.size() - 1);
|
||||
}
|
||||
|
||||
QList<QString> lib_syntax::Seqs::invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const {
|
||||
QList<QString> lines;
|
||||
|
||||
lines << QString(u8"if (%1->mustStop())").arg(in_cursor_name);
|
||||
lines << QString(u8" return QList<std::shared_ptr<const MatchCursor>>() << %1; ").arg(in_cursor_name);
|
||||
|
||||
int times = 0;
|
||||
lines << QString(u8"QList<std::shared_ptr<const MatchCursor>> bridge_list{ %1 };").arg(in_cursor_name);
|
||||
for (auto rule : children()) {
|
||||
auto segments = rule->invokeSegments(in_cursor_name, QString(u8"result_list_%1").arg((uint64_t) this));
|
||||
if (segments.size() == 1) {
|
||||
lines.append(segments);
|
||||
}
|
||||
else {
|
||||
lines << u8"{";
|
||||
lines.append(segments);
|
||||
lines << u8"}";
|
||||
}
|
||||
}
|
||||
lines << QString(u8"%2 = result_list_%1;").arg((uint64_t) this).arg(out_list_name);
|
||||
}
|
||||
|
||||
Rept::Rept(std::shared_ptr<const IBasicRule> rule, int min, int max)
|
||||
: rule_peer(rule), min_match(min), max_match(max) { }
|
||||
|
||||
|
@ -193,6 +240,53 @@ QString ExprRule::present() const {
|
|||
return child_store->present();
|
||||
}
|
||||
|
||||
QList<QString> lib_syntax::ExprRule::invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const {
|
||||
return QList<QString>() << QString(u8"%1=exprs_%2(%3); //%4")
|
||||
.arg(out_list_name).arg((uint64_t) this).arg(in_cursor_name).arg(name());
|
||||
}
|
||||
|
||||
QString lib_syntax::ExprRule::implementSegments(const QString& in_cursor_name, QList<QString>& lines) const {
|
||||
lines << u8"if (" + in_cursor_name + "->mustStop())";
|
||||
lines << u8" return QList<std::shared_ptr<const MatchCursor>>() << " + in_cursor_name + ";";
|
||||
lines << u8"auto t_this = " + in_cursor_name + "->currentToken();";
|
||||
lines << u8"auto w_this = " + in_cursor_name + "->currentWords();";
|
||||
lines << u8"auto split_begin = std::make_shared<lib_token::ExprBeginToken<ExprType>>(shared_from_this(), t_this);";
|
||||
lines << u8"auto ncursor = std::make_shared<MatchCursor>(" + in_cursor_name + ");";
|
||||
lines << u8"ncursor->setCurrent(split_begin, w_this);";
|
||||
lines << u8"ncursor->enterExprs();";
|
||||
lines << u8"auto nbranch = this->child_store->parse(ncursor);";
|
||||
lines << u8"decltype(nbranch) list_ok;";
|
||||
lines << u8"// 选择完全匹配成功的";
|
||||
lines << u8"std::copy_if(nbranch.begin(), nbranch.end(), std::back_inserter(list_ok),"
|
||||
"[](std::shared_ptr<const MatchCursor> ins) { return !ins->exprsErrorCount(); });";
|
||||
lines << u8"if (!list_ok.size()) {";
|
||||
lines << u8" // 选择被修正的";
|
||||
lines << u8" std::copy_if(nbranch.begin(), nbranch.end(), std::back_inserter(list_ok),"
|
||||
"[](std::shared_ptr<const MatchCursor> ins) { return !ins->mustStop(); });";
|
||||
lines << u8" // 匹配失败的";
|
||||
lines << u8" if (!list_ok.size())";
|
||||
lines << u8" list_ok = nbranch;";
|
||||
lines << u8"}";
|
||||
lines << u8"decltype(list_ok) branch_procs;";
|
||||
lines << u8"std::for_each(list_ok.begin(), list_ok.end(), [&](std::shared_ptr<const MatchCursor> curs) {";
|
||||
lines << u8" if (curs->mustStop()) {";
|
||||
lines << u8" branch_procs.append(curs);";
|
||||
lines << u8" }";
|
||||
lines << u8" else {";
|
||||
lines << u8" auto t_end = curs->currentToken();";
|
||||
lines << u8" auto w_end = curs->currentWords();";
|
||||
lines << u8" auto ecursor = std::make_shared<MatchCursor>(curs);";
|
||||
lines << u8" ecursor->quitExprs();";
|
||||
lines << u8" auto split_end = std::make_shared<lib_token::ExprEndToken<ExprType>>(split_begin, t_end);";
|
||||
lines << u8" ecursor->setCurrent(split_end, w_end);";
|
||||
lines << u8" branch_procs.append(ecursor);";
|
||||
lines << u8" }";
|
||||
lines << u8"});";
|
||||
lines << u8"return branch_procs;";
|
||||
|
||||
return QString(u8"exprs_%1").arg((uint64_t) this);
|
||||
}
|
||||
|
||||
MatchCursor::MatchCursor(const QString& path) :_file_path(path) { }
|
||||
|
||||
MatchCursor::MatchCursor(std::shared_ptr<const MatchCursor> other_ptr)
|
||||
|
|
|
@ -90,9 +90,8 @@ namespace lib_syntax {
|
|||
|
||||
/**
|
||||
* @brief ½âÎö
|
||||
* @param rt_inst 解析上下文
|
||||
* @param head 列表头
|
||||
* @return 返回结果<匹配完成新列表头,匹配长度>
|
||||
* @param cursor 解析游标
|
||||
* @return 返回结果<匹配分支>
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const = 0;
|
||||
|
||||
|
@ -101,6 +100,27 @@ namespace lib_syntax {
|
|||
* @return
|
||||
*/
|
||||
virtual QList<std::shared_ptr<const IBasicRule>> children() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 翻译此规则
|
||||
* @param in_cursor_name 指定输入cursor名称
|
||||
* @param out_list_name 指定输出list名称
|
||||
*
|
||||
*
|
||||
* out_list_name = element_xxxxxx(in_cursor_name);
|
||||
* ……
|
||||
* @return 返回执行语句段
|
||||
*/
|
||||
virtual QList<QString> invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const = 0;
|
||||
|
||||
/**
|
||||
* @brief 定义和实现语句
|
||||
* @param in_cursor_name 输入
|
||||
* @param lines 规则实现语句
|
||||
*
|
||||
* @return 表达式规则名称
|
||||
*/
|
||||
virtual QString implementSegments(const QString& in_cursor_name, QList<QString>& lines) const = 0;
|
||||
};
|
||||
|
||||
// ×éºÏÓ﷨ʵÌå½âÎö =====================================================================================
|
||||
|
@ -119,6 +139,9 @@ namespace lib_syntax {
|
|||
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const override;
|
||||
virtual QString present() const override;
|
||||
|
||||
virtual QList<QString> invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const override;
|
||||
virtual QString implementSegments(const QString& in_cursor_name, QList<QString>& lines) const override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -136,6 +159,9 @@ namespace lib_syntax {
|
|||
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
|
||||
virtual QList<std::shared_ptr<const MatchCursor>> parse(std::shared_ptr<const MatchCursor> cursor) const override;
|
||||
virtual QString present() const override;
|
||||
|
||||
virtual QList<QString> invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const override;
|
||||
virtual QString implementSegments(const QString& in_cursor_name, QList<QString>& lines) const override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -171,6 +197,8 @@ namespace lib_syntax {
|
|||
public:
|
||||
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
|
||||
virtual QString present() const override;
|
||||
virtual QList<QString> invokeSegments(const QString& in_cursor_name, const QString& out_list_name) const override;
|
||||
virtual QString implementSegments(const QString& in_cursor_name, QList<QString> &lines) const override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<const IBasicRule> child_store;
|
||||
|
|
Loading…
Reference in New Issue