framework-update

This commit is contained in:
codeboss 2024-07-25 17:08:24 +08:00
parent c277af9c36
commit a92b4cacc1
2 changed files with 31 additions and 21 deletions

View File

@ -52,26 +52,26 @@ QList<ParseFork> TokenMatch::parse(const ParseFork& context) const
} }
// 缺一个 // 缺一个
ParseFork absence_fork(context); ParseFork absence_fork(context);
result_list << absence_fork;
absence_fork.error_messages << QString(u8"Syntax[0x0002]缺失Token'%1'<row:%2,col:%3>)。") absence_fork.error_messages << QString(u8"Syntax[0x0002]缺失Token'%1'<row:%2,col:%3>)。")
.arg(this->token_present()).arg(head->row()).arg(head->column()); .arg(this->token_present()).arg(head->row()).arg(head->column());
absence_fork.next = head; absence_fork.next = head;
absence_fork.occurs = ErrDeals::Absence; absence_fork.occurs = ErrDeals::Absence;
result_list << absence_fork;
// 错一个 // 错一个
ParseFork replace_fork(context); ParseFork replace_fork(context);
result_list << replace_fork;
replace_fork.error_messages << QString(u8"Syntax[0x0003]纠正Token'%1'<row:%2,col:%3>,应该为'%4')。") replace_fork.error_messages << QString(u8"Syntax[0x0003]纠正Token'%1'<row:%2,col:%3>,应该为'%4')。")
.arg(head->content()).arg(head->row()).arg(head->column()).arg(this->token_present()); .arg(head->content()).arg(head->row()).arg(head->column()).arg(this->token_present());
replace_fork.next = head->nextWord(); replace_fork.next = head->nextWord();
replace_fork.occurs = ErrDeals::Replace; replace_fork.occurs = ErrDeals::Replace;
result_list << replace_fork;
// 多一个 // 多一个
auto temp_head = head->nextWord(); auto temp_head = head->nextWord();
if(temp_head){
auto match_result = define_peer->analysis(temp_head); auto match_result = define_peer->analysis(temp_head);
if (get<0>(match_result)) { if (get<0>(match_result)) {
ParseFork surplus_fork(context); ParseFork surplus_fork(context);
result_list << surplus_fork;
surplus_fork.error_messages << QString(u8"Syntax[0x0004]发现冗余Token'%1'<row:%2,col:%3>)。") surplus_fork.error_messages << QString(u8"Syntax[0x0004]发现冗余Token'%1'<row:%2,col:%3>)。")
.arg(head->content()).arg(head->row()).arg(head->column()); .arg(head->content()).arg(head->row()).arg(head->column());
surplus_fork.occurs = ErrDeals::Surplus; surplus_fork.occurs = ErrDeals::Surplus;
@ -81,6 +81,9 @@ QList<ParseFork> TokenMatch::parse(const ParseFork& context) const
surplus_fork.next = make_shared<WordImpl>(get<1>(match_result), temp_head->nextWord()); surplus_fork.next = make_shared<WordImpl>(get<1>(match_result), temp_head->nextWord());
else else
surplus_fork.next = temp_head->nextWord(); surplus_fork.next = temp_head->nextWord();
result_list << surplus_fork;
}
} }
} }
return result_list; return result_list;
@ -191,6 +194,12 @@ QList<ParseFork> Rept::parse(const ParseFork& context) const {
QString Rept::token_present() const QString Rept::token_present() const
{ {
if (min_match == 0 && max_match == INT_MAX)
return u8"(" + this->rule_peer->token_present() + QString(u8")*");
if (min_match == 1 && max_match == INT_MAX)
return u8"(" + this->rule_peer->token_present() + QString(u8")+");
return u8"(" + this->rule_peer->token_present() + QString(u8"){%1, %2}").arg(min_match).arg(max_match); return u8"(" + this->rule_peer->token_present() + QString(u8"){%1, %2}").arg(min_match).arg(max_match);
} }
@ -233,8 +242,8 @@ QString Seqs::token_present() const
{ {
QString content; QString content;
for (auto& it : children()) for (auto& it : children())
content += it->token_present(); content += it->token_present() + u8" ";
return content; return content.mid(0, content.size() -1);
} }
@ -247,6 +256,7 @@ QList<ParseFork> Any::parse(const ParseFork& context) const {
QList<ParseFork> temp_results; QList<ParseFork> temp_results;
for (auto& fork : mbrs_store) { for (auto& fork : mbrs_store) {
auto fork_present = fork->token_present();
auto result_forks = fork->parse(context); auto result_forks = fork->parse(context);
for (auto rst_fork : result_forks) { for (auto rst_fork : result_forks) {
switch (rst_fork.occurs) { switch (rst_fork.occurs) {

View File

@ -26,7 +26,7 @@ std::shared_ptr<const IWordBase> lib_token::TokenContent::nextWord() const
std::shared_ptr<const ITokenDefine> TokenContent::define() const { return this->type_def; } std::shared_ptr<const ITokenDefine> TokenContent::define() const { return this->type_def; }
QString LeftBracket::reviseWords() const { return u8"{"; } QString LeftBracket::reviseWords() const { return u8"'{'"; }
int LeftBracket::typeMark() const int LeftBracket::typeMark() const
{ {
@ -53,7 +53,7 @@ LeftBracket::analysis(std::shared_ptr<const IWordBase> content) const {
return std::make_tuple(token_inst, nullptr); return std::make_tuple(token_inst, nullptr);
} }
QString RightBracket::reviseWords() const { return u8"}"; } QString RightBracket::reviseWords() const { return u8"'}'"; }
int RightBracket::typeMark() const int RightBracket::typeMark() const
{ {
@ -62,7 +62,7 @@ int RightBracket::typeMark() const
QString RightBracket::regex() const { return u8"}"; } QString RightBracket::regex() const { return u8"}"; }
QString ReferMark::reviseWords() const { return u8"@"; } QString ReferMark::reviseWords() const { return u8"'@'"; }
int ReferMark::typeMark() const int ReferMark::typeMark() const
{ {
@ -144,7 +144,7 @@ VTextSection::analysis(std::shared_ptr<const IWordBase> content) const {
return std::make_tuple(tinst, nullptr); return std::make_tuple(tinst, nullptr);
} }
QString Split::reviseWords() const { return u8"&"; } QString Split::reviseWords() const { return u8"'&'"; }
int Split::typeMark() const int Split::typeMark() const
{ {