slash-version
This commit is contained in:
parent
367140bef2
commit
26eab5a092
|
@ -41,11 +41,15 @@ ParseResult TokenMatch::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWo
|
||||||
case lib_syntax::ErrDeals::Replace:
|
case lib_syntax::ErrDeals::Replace:
|
||||||
fx_type = ErrDeals::None;
|
fx_type = ErrDeals::None;
|
||||||
result_ret.result_repair = make_tuple(MatchResult::Success, head->nextWord());
|
result_ret.result_repair = make_tuple(MatchResult::Success, head->nextWord());
|
||||||
|
rt_inst->appendParseError(rt_inst->currentFile(), head->position(), QString(u8"指定Token<row:%3,col:%4>“%1”匹配错误,应为“%2”。")
|
||||||
|
.arg(head->content()).arg(this->define_peer->reviseWords()).arg(head->row()).arg(head->column()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lib_syntax::ErrDeals::Absence:
|
case lib_syntax::ErrDeals::Absence:
|
||||||
fx_type = ErrDeals::None;
|
fx_type = ErrDeals::None;
|
||||||
result_ret.result_repair = make_tuple(MatchResult::Success, head);
|
result_ret.result_repair = make_tuple(MatchResult::Success, head);
|
||||||
|
rt_inst->appendParseError(rt_inst->currentFile(), head->position(), QString(u8"指定位置缺失Token<row:%2,col:%3>,应为“%1”。")
|
||||||
|
.arg(this->define_peer->reviseWords()).arg(head->row()).arg(head->column()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lib_syntax::ErrDeals::Surplus:
|
case lib_syntax::ErrDeals::Surplus:
|
||||||
|
@ -54,6 +58,9 @@ ParseResult TokenMatch::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWo
|
||||||
auto temp_head = head->nextWord();
|
auto temp_head = head->nextWord();
|
||||||
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)) {
|
||||||
|
rt_inst->appendParseError(rt_inst->currentFile(), head->position(), QString(u8"发现冗余Token<row:%2,col:%3>,内容为“%1”。")
|
||||||
|
.arg(head->content()).arg(head->row()).arg(head->column()));
|
||||||
|
|
||||||
rt_inst->currentExprInst()->addToken(get<0>(match_result));
|
rt_inst->currentExprInst()->addToken(get<0>(match_result));
|
||||||
if (get<1>(match_result))
|
if (get<1>(match_result))
|
||||||
result_ret.result_repair = make_tuple(MatchResult::Success, make_shared<WordImpl>(get<1>(match_result), temp_head->nextWord()));
|
result_ret.result_repair = make_tuple(MatchResult::Success, make_shared<WordImpl>(get<1>(match_result), temp_head->nextWord()));
|
||||||
|
@ -84,60 +91,77 @@ Rept::Rept(shared_ptr<const IBasicRule> rule, int min, int max) : rule_peer(rule
|
||||||
QList<shared_ptr<const IBasicRule>> Rept::children() const { return QList<shared_ptr<const IBasicRule>>() << rule_peer; }
|
QList<shared_ptr<const IBasicRule>> Rept::children() const { return QList<shared_ptr<const IBasicRule>>() << rule_peer; }
|
||||||
|
|
||||||
ParseResult Rept::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const {
|
ParseResult Rept::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const {
|
||||||
ParseResult result_final;
|
ParseResult fnl_result;
|
||||||
|
|
||||||
bool straight_mark = fx_type == ErrDeals::None;
|
|
||||||
auto temp_head = head;
|
auto temp_head = head;
|
||||||
// min-match
|
auto initial_fxtype = ErrDeals::None;
|
||||||
for (auto idx = 0; idx < min_match; ++idx) {
|
|
||||||
auto result_gen = rule_peer->parse(rt_inst, temp_head, fx_type);
|
|
||||||
auto v_result = result_gen.result_straight;
|
|
||||||
if (std::get<0>(v_result) == MatchResult::None)
|
|
||||||
v_result = result_gen.result_repair;
|
|
||||||
|
|
||||||
switch (std::get<0>(v_result)) {
|
retry_entry:
|
||||||
case MatchResult::Part:
|
switch (initial_fxtype) {
|
||||||
if (straight_mark)
|
case lib_syntax::ErrDeals::Surplus:
|
||||||
result_final.result_straight = make_tuple(MatchResult::Part, std::get<1>(v_result));
|
case lib_syntax::ErrDeals::Absence:
|
||||||
else
|
case lib_syntax::ErrDeals::Replace:
|
||||||
result_final.result_repair = make_tuple(MatchResult::Part, std::get<1>(v_result));
|
|
||||||
return result_final;
|
|
||||||
|
|
||||||
default:
|
|
||||||
temp_head = std::get<1>(v_result);
|
break;
|
||||||
break;
|
case lib_syntax::ErrDeals::None:
|
||||||
|
// min-match
|
||||||
|
for (auto idx = 0; idx < min_match; ++idx) {
|
||||||
|
auto result_genx = rule_peer->parse(rt_inst, temp_head, initial_fxtype);
|
||||||
|
|
||||||
|
switch (std::get<0>(result_genx.result_straight)) {
|
||||||
|
case MatchResult::Part:
|
||||||
|
if(fx_type == ErrDeals::None)
|
||||||
|
return result_genx;
|
||||||
|
|
||||||
|
initial_fxtype = fx_type;
|
||||||
|
temp_head = head;
|
||||||
|
goto retry_entry;
|
||||||
|
|
||||||
|
default:
|
||||||
|
temp_head = std::get<1>(result_genx.result_straight);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// max-match
|
||||||
|
for (auto idx = min_match; idx < max_match; ++idx) {
|
||||||
|
if (!temp_head)
|
||||||
|
break;
|
||||||
|
|
||||||
|
auto result_genx = rule_peer->parse(rt_inst, temp_head, initial_fxtype);
|
||||||
|
auto v_result = result_genx.result_straight;
|
||||||
|
if (std::get<0>(v_result) == MatchResult::None) {
|
||||||
|
v_result = result_genx.result_repair;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (get<0>(v_result)) {
|
||||||
|
case MatchResult::Part:
|
||||||
|
if (straight_flags)
|
||||||
|
fnl_result.result_straight = v_result;
|
||||||
|
else
|
||||||
|
fnl_result.result_repair = v_result;
|
||||||
|
return fnl_result;
|
||||||
|
|
||||||
|
default:
|
||||||
|
temp_head = get<1>(v_result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// max-match
|
|
||||||
for (auto idx = min_match; idx < max_match; ++idx) {
|
|
||||||
if (!temp_head)
|
|
||||||
break;
|
|
||||||
|
|
||||||
auto result_gen = rule_peer->parse(rt_inst, temp_head, fx_type);
|
if(straight_flags)
|
||||||
auto v_result = result_gen.result_straight;
|
fnl_result.result_straight = make_tuple(MatchResult::Success, temp_head);
|
||||||
if (std::get<0>(v_result) == MatchResult::None)
|
|
||||||
v_result = result_gen.result_repair;
|
|
||||||
|
|
||||||
switch (get<0>(v_result)) {
|
|
||||||
case MatchResult::Part:
|
|
||||||
if(straight_mark)
|
|
||||||
result_final.result_straight = make_tuple(MatchResult::Success, temp_head);
|
|
||||||
else
|
|
||||||
result_final.result_repair = make_tuple(MatchResult::Success, temp_head);
|
|
||||||
return result_final;
|
|
||||||
|
|
||||||
default:
|
|
||||||
temp_head = get<1>(v_result);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(straight_mark)
|
|
||||||
result_final.result_straight = make_tuple(MatchResult::Success, temp_head);
|
|
||||||
else
|
else
|
||||||
result_final.result_repair = make_tuple(MatchResult::Success, temp_head);
|
fnl_result.result_repair = make_tuple(MatchResult::Success, temp_head);
|
||||||
return result_final;
|
|
||||||
|
fx_type = initial_fxtype;
|
||||||
|
return fnl_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Rept::token_present() const
|
QString Rept::token_present() const
|
||||||
|
@ -159,12 +183,12 @@ ParseResult Seqs::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase
|
||||||
auto rst_gene = r->parse(rt_inst, temp_head, fx_type);
|
auto rst_gene = r->parse(rt_inst, temp_head, fx_type);
|
||||||
|
|
||||||
auto v_result = rst_gene.result_straight;
|
auto v_result = rst_gene.result_straight;
|
||||||
if(std::get<0>(v_result) == MatchResult::None)
|
if (std::get<0>(v_result) == MatchResult::None)
|
||||||
v_result = rst_gene.result_repair;
|
v_result = rst_gene.result_repair;
|
||||||
|
|
||||||
switch (get<0>(v_result)) {
|
switch (get<0>(v_result)) {
|
||||||
case MatchResult::Part:
|
case MatchResult::Part:
|
||||||
if(straight_mark)
|
if (straight_mark)
|
||||||
result_final.result_straight = v_result;
|
result_final.result_straight = v_result;
|
||||||
else
|
else
|
||||||
result_final.result_repair = v_result;
|
result_final.result_repair = v_result;
|
||||||
|
@ -201,38 +225,85 @@ QList<shared_ptr<const IBasicRule>> Any::children() const { return mbrs_store; }
|
||||||
ParseResult Any::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const {
|
ParseResult Any::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const {
|
||||||
auto rule_present = this->token_present();
|
auto rule_present = this->token_present();
|
||||||
|
|
||||||
ParseResult result_final;
|
std::tuple<std::shared_ptr<const IBasicRule>, uint64_t> temp_result = std::make_tuple(nullptr, 0);
|
||||||
bool straight_mark = fx_type == ErrDeals::None;
|
bool straight_mark = fx_type ==
|
||||||
|
|
||||||
switch (fx_type) {
|
switch (fx_type) {
|
||||||
case ErrDeals::None: {
|
case ErrDeals::None: {
|
||||||
for (auto& fork : mbrs_store) {
|
ParseResult result_final;
|
||||||
auto gen = fork->parse(rt_inst, head, fx_type);
|
for (auto& fork : mbrs_store) {
|
||||||
|
auto xgen = fork->parse(rt_inst, head, fx_type);
|
||||||
|
|
||||||
switch (get<0>(gen.result_straight)) {
|
auto v_result = xgen.result_straight;
|
||||||
// 遇到成功的直接返回解析结果
|
if (std::get<0>(v_result) == MatchResult::None)
|
||||||
case MatchResult::Success:
|
v_result = xgen.result_repair;
|
||||||
return gen;
|
|
||||||
|
|
||||||
case MatchResult::Part: {
|
switch (get<0>(v_result)) {
|
||||||
auto span = get<1>(gen)->position() - head->position();
|
// 遇到成功的直接返回解析结果
|
||||||
if (span >= get<1>(temp_result))
|
case MatchResult::Success:
|
||||||
temp_result = make_tuple(fork, span);
|
return gen;
|
||||||
|
|
||||||
|
case MatchResult::Part: {
|
||||||
|
auto span = get<1>(gen.result_straight)->position() - head->position();
|
||||||
|
if (span >= get<1>(temp_result))
|
||||||
|
temp_result = make_tuple(fork, span);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
break;
|
for (auto& itfx : QList<ErrDeals>{ ErrDeals::Surplus, ErrDeals::Absence, ErrDeals::Replace }) {
|
||||||
|
auto fix_current = itfx;
|
||||||
|
auto repair_result = this->parse(rt_inst, head, fix_current);
|
||||||
|
|
||||||
|
auto v_result = repair_result.result_straight;
|
||||||
|
if (std::get<0>(v_result) == MatchResult::None)
|
||||||
|
v_result = repair_result.result_repair;
|
||||||
|
|
||||||
|
switch (std::get<0>(v_result)) {
|
||||||
|
case MatchResult::Success:
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}break;
|
||||||
|
|
||||||
|
default: {
|
||||||
|
ParseResult inst;
|
||||||
|
|
||||||
|
for (auto& fork : mbrs_store) {
|
||||||
|
auto fx_init = fx_type;
|
||||||
|
|
||||||
|
auto gen = fork->parse(rt_inst, head, fx_init);
|
||||||
|
auto v_result = gen.result_straight;
|
||||||
|
if (std::get<0>(v_result) == MatchResult::None)
|
||||||
|
v_result = gen.result_repair;
|
||||||
|
|
||||||
|
switch (std::get<0>(v_result)) {
|
||||||
|
case MatchResult::Success:
|
||||||
|
inst.result_repair = v_result;
|
||||||
|
fx_type = fx_init;
|
||||||
|
return inst;
|
||||||
|
|
||||||
|
default: {
|
||||||
|
auto span = std::get<1>(v_result)->position() - head->position();
|
||||||
|
if (span >= std::get<1>(temp_result))
|
||||||
|
temp_result = std::make_tuple(fork, span);
|
||||||
|
}break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}break;
|
||||||
}
|
}
|
||||||
// 分析最匹配的分支
|
|
||||||
rt_inst->clearErrors(rt_inst->currentFile(), head->position());
|
|
||||||
auto temp = get<0>(temp_result)->parse(rt_inst, head, fx_type);
|
|
||||||
return make_tuple(MatchResult::Part, get<1>(temp));
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 分析最匹配的分支
|
||||||
|
rt_inst->clearErrors(rt_inst->currentFile(), head->position());
|
||||||
|
auto temp = get<0>(temp_result)->parse(rt_inst, head, fx_type);
|
||||||
|
return make_tuple(MatchResult::Part, get<1>(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Any::token_present() const
|
QString Any::token_present() const
|
||||||
|
|
Loading…
Reference in New Issue