改进错误提示

This commit is contained in:
codeboss 2024-07-25 11:54:40 +08:00
parent da598a5ba6
commit 90104e0e9e
1 changed files with 13 additions and 7 deletions

View File

@ -23,8 +23,9 @@ std::tuple<IBasicRule::MatchResult, std::shared_ptr<const IWordBase>> TokenMatch
} }
else { else {
rt_inst->appendParseErrors(rt_inst->currentFile(), head->position(), rt_inst->appendParseErrors(rt_inst->currentFile(), head->position(),
QString(u8"Syntax[0x00001]语法匹配错误不能识别token\"%1\"<row:%2,col:%3>(应该为:%4)") QString(u8"Syntax[0x00001]语法匹配错误,无法识别\"%1\"<row:%2,col:%3>(应该为:%4)\n\t目标语法:'%5'。\n")
.arg(head->content()).arg(head->row()).arg(head->column()).arg(this->define_peer->reviseWords())); .arg(head->content()).arg(head->row()).arg(head->column()).arg(this->define_peer->reviseWords())
.arg(rt_inst->currentExprRule()->token_present()));
return std::make_tuple(IBasicRule::MatchResult::Part, head); return std::make_tuple(IBasicRule::MatchResult::Part, head);
} }
@ -37,7 +38,7 @@ std::tuple<IBasicRule::MatchResult, std::shared_ptr<const IWordBase>> TokenMatch
} }
QString TokenMatch::token_present() const { QString TokenMatch::token_present() const {
return QString(u8"<%1>").arg(this->define_peer->reviseWords()); return QString(u8"%1").arg(this->define_peer->reviseWords());
} }
Rept::Rept(std::shared_ptr<const IBasicRule> rule, int min, int max) : rule_peer(rule), min_match(min), max_match(max) {} Rept::Rept(std::shared_ptr<const IBasicRule> rule, int min, int max) : rule_peer(rule), min_match(min), max_match(max) {}
@ -82,7 +83,12 @@ std::tuple<IBasicRule::MatchResult, std::shared_ptr<const IWordBase>> Rept::pars
QString Rept::token_present() const QString Rept::token_present() const
{ {
return u8"(" + this->rule_peer->token_present() + QString(u8"{%1, %2}").arg(min_match).arg(max_match) + u8")"; if(min_match == 0 && max_match == INT_MAX)
return u8"(" + this->rule_peer->token_present() + QString(u8")*");
else 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);
} }
Seqs::Seqs(const QList<std::shared_ptr<const IBasicRule>> mbrs) : mbrs_store(mbrs) {} Seqs::Seqs(const QList<std::shared_ptr<const IBasicRule>> mbrs) : mbrs_store(mbrs) {}
@ -114,8 +120,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() + " ";
return QString(u8"(%1)").arg(content); return content.mid(0, content.size() - 1);
} }
//std::tuple<IBasicRule::MatchResult, uint, std::shared_ptr<const IBasicRule>, std::shared_ptr<const Token>> //std::tuple<IBasicRule::MatchResult, uint, std::shared_ptr<const IBasicRule>, std::shared_ptr<const Token>>
@ -171,7 +177,7 @@ QString Any::token_present() const
for (auto& it : children()) { for (auto& it : children()) {
members_content += it->token_present() + u8"|"; members_content += it->token_present() + u8"|";
} }
return u8"(" + members_content.mid(0, members_content.size() - 1) + u8")"; return members_content.mid(0, members_content.size() - 1);
} }