Compare commits

...

2 Commits

Author SHA1 Message Date
codeboss 367140bef2 更新 2024-07-21 10:40:43 +08:00
codeboss f58a034df2 slash 2024-07-19 22:01:55 +08:00
8 changed files with 214 additions and 191 deletions

View File

@ -42,7 +42,9 @@ QList<std::shared_ptr<const ast_basic::IExprInst>> NovelParser::parse(const QFil
for (auto& file : source_list) {
context->setCurrentFile(file.canonicalFilePath());
auto words = word_reader->wordsFrom(file.canonicalFilePath());
this->syntax_defines->parse(context, words);
lib_syntax::IBasicRule::ErrDeals modify = lib_syntax::IBasicRule::ErrDeals::None;
this->syntax_defines->parse(context, words, modify);
}
QList<std::shared_ptr<const ast_basic::IExprInst>> forst_root = context->getDocInsts();

View File

@ -76,7 +76,7 @@ std::shared_ptr<const IBasicRule> ExpressionContext::popExprRule()
return rule_stack.takeLast();
}
void ExpressionContext::appendParseErrors(const QString& file_path, int start, const QString& e) {
void ExpressionContext::appendParseError(const QString& file_path, int start, const QString& e) {
this->errors_storage.append(std::make_tuple(file_path, start, e));
}

View File

@ -104,7 +104,7 @@ namespace ast_basic {
virtual void appendDocInst(std::shared_ptr<ast_basic::IExprInst> inst) override;
virtual QList<std::shared_ptr<const ast_basic::IExprInst>> getDocInsts() const override;
void appendParseErrors(const QString& file_path, int start, const QString& error_msg) override;
void appendParseError(const QString& file_path, int start, const QString& error_msg) override;
QStringList errors() const override;
void clearErrors(const QString& file_path, int start) override;
};

View File

@ -184,14 +184,15 @@ namespace lib_syntax {
}
virtual std::tuple<IBasicRule::MatchResult, std::shared_ptr<const lib_token::IWordBase>>
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head) const override {
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, IBasicRule::ErrDeals &fx_type) const override {
std::shared_ptr<ast_basic::IExprInst> elm_ast = this->newEmptyInstance();
auto text_present = this->token_present();
rt_inst->pushExprRule(this->shared_from_this());
rt_inst->pushExprInst(elm_ast);
auto rstg = child_store->parse(rt_inst, head);
IBasicRule::ErrDeals fixed = IBasicRule::ErrDeals::None;
auto rstg = child_store->parse(rt_inst, head, fixed);
auto tokens_decl = elm_ast->tokens();
switch (std::get<0>(rstg)) {
@ -202,7 +203,7 @@ namespace lib_syntax {
break;
case IBasicRule::MatchResult::Success: {
if (!std::dynamic_pointer_cast<example_novel::Document>(elm_ast)) {
auto start_pos = tokens_decl.first()->position();
auto start_pos = head->position();
rt_inst->clearErrors(rt_inst->currentFile(), start_pos);
}

View File

@ -11,92 +11,100 @@ TokenMatch::TokenMatch(shared_ptr<const ITokenDefine> define) : define_peer(defi
QList<shared_ptr<const IBasicRule>> TokenMatch::children() const { return QList<shared_ptr<const IBasicRule>>(); }
tuple<IBasicRule::MatchResult, shared_ptr<const IWordBase>>
TokenMatch::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrOccurs& fx_type) const
ParseResult TokenMatch::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const
{
if (!head) {
rt_inst->appendParseError(rt_inst->currentFile(), -1, QString(u8"Syntax[0x0000]tokenÁ÷£¨%1£©ÌáǰÖÕÖ¹").arg(rt_inst->currentFile()));
return make_tuple(IBasicRule::MatchResult::Fail, head);
return ParseResult();
}
ParseResult result_ret;
auto match_result = define_peer->analysis(head);
if (get<0>(match_result)) {
rt_inst->currentExprInst()->addToken(get<0>(match_result));
decltype(result_ret.result_repair) v_result;
if (get<1>(match_result)) {
return make_tuple(IBasicRule::MatchResult::Success, make_shared<WordImpl>(get<1>(match_result), head->nextWord()));
v_result = make_tuple(MatchResult::Success, make_shared<WordImpl>(get<1>(match_result), head->nextWord()));
}
else {
return make_tuple(IBasicRule::MatchResult::Success, head->nextWord());
v_result = make_tuple(MatchResult::Success, head->nextWord());
}
if (fx_type == ErrDeals::None)
result_ret.result_straight = v_result;
else
result_ret.result_repair = v_result;
}
else {
switch (fx_type) {
case lib_syntax::IBasicRule::ErrOccurs::None:
return make_tuple(IBasicRule::MatchResult::Part, head);
case lib_syntax::IBasicRule::ErrOccurs::Replace:
fx_type = IBasicRule::ErrOccurs::None;
rt_inst->appendParseError(rt_inst->currentFile(), head->position(),
QString(u8"Syntax[0x00001]语法匹配错误不能识别token\"%1\"<row:%2,col:%3>(应该为:%4)")
.arg(head->content()).arg(head->row()).arg(head->column()).arg(this->define_peer->reviseWords()));
return make_tuple(IBasicRule::MatchResult::Success, head->nextWord());
case lib_syntax::IBasicRule::ErrOccurs::Absence:
fx_type = IBasicRule::ErrOccurs::None;
rt_inst->appendParseError(rt_inst->currentFile(), head->position(),
QString(u8"Syntax[0x00001]语法匹配错误缺少token\"%1\"<row: % 2, col : % 3>")
.arg(this->define_peer->reviseWords()).arg(head->row()).arg(head->column()));
return make_tuple(IBasicRule::MatchResult::Success, head);
case lib_syntax::IBasicRule::ErrOccurs::Surplus:
fx_type = IBasicRule::ErrOccurs::None;
case lib_syntax::ErrDeals::Replace:
fx_type = ErrDeals::None;
result_ret.result_repair = make_tuple(MatchResult::Success, head->nextWord());
break;
case lib_syntax::ErrDeals::Absence:
fx_type = ErrDeals::None;
result_ret.result_repair = make_tuple(MatchResult::Success, head);
break;
case lib_syntax::ErrDeals::Surplus:
fx_type = ErrDeals::None;
{
auto temp_head = head->nextWord();
auto match_result = define_peer->analysis(temp_head);
if (get<0>(match_result)) {
rt_inst->appendParseError(rt_inst->currentFile(), head->position(),
QString(u8"Syntax[0x00001]语法匹配错误多余token\"%1\"<row: % 2, col : % 3>")
.arg(head->content()).arg(head->row()).arg(head->column()));
rt_inst->currentExprInst()->addToken(get<0>(match_result));
if (get<1>(match_result)) {
return make_tuple(IBasicRule::MatchResult::Success, make_shared<WordImpl>(get<1>(match_result), temp_head->nextWord()));
}
else {
return make_tuple(IBasicRule::MatchResult::Success, temp_head->nextWord());
}
if (get<1>(match_result))
result_ret.result_repair = make_tuple(MatchResult::Success, make_shared<WordImpl>(get<1>(match_result), temp_head->nextWord()));
else
result_ret.result_repair = make_tuple(MatchResult::Success, temp_head->nextWord());
}
else {
return make_tuple(IBasicRule::MatchResult::Part, head);
result_ret.result_repair = make_tuple(MatchResult::Part, head);
}
}
break;
default:
result_ret.result_straight = make_tuple(MatchResult::Part, head);
break;
}
}
return result_ret;
}
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(shared_ptr<const IBasicRule> rule, int min, int max) : rule_peer(rule), min_match(min), max_match(max) {}
QList<shared_ptr<const IBasicRule>> Rept::children() const { return QList<shared_ptr<const IBasicRule>>() << rule_peer; }
tuple<IBasicRule::MatchResult, shared_ptr<const IWordBase>>
Rept::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, IBasicRule::ErrOccurs& fx_type) const {
auto temp_head = head;
ParseResult Rept::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const {
ParseResult result_final;
bool straight_mark = fx_type == ErrDeals::None;
auto temp_head = head;
// min-match
for (auto idx = 0; idx < min_match; ++idx) {
auto result_gen = rule_peer->parse(rt_inst, temp_head, fx_type);
switch (get<0>(result_gen)) {
case IBasicRule::MatchResult::Fail:
return make_tuple(IBasicRule::MatchResult::Part, temp_head);
case IBasicRule::MatchResult::Part:
return make_tuple(IBasicRule::MatchResult::Part, get<1>(result_gen));
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)) {
case MatchResult::Part:
if (straight_mark)
result_final.result_straight = make_tuple(MatchResult::Part, std::get<1>(v_result));
else
result_final.result_repair = make_tuple(MatchResult::Part, std::get<1>(v_result));
return result_final;
default:
temp_head = get<1>(result_gen);
temp_head = std::get<1>(v_result);
break;
}
}
@ -107,48 +115,74 @@ Rept::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, IBas
break;
auto result_gen = rule_peer->parse(rt_inst, temp_head, fx_type);
switch (get<0>(result_gen)) {
case IBasicRule::MatchResult::Fail:
case IBasicRule::MatchResult::Part:
return make_tuple(IBasicRule::MatchResult::Success, temp_head);
auto v_result = result_gen.result_straight;
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>(result_gen);
temp_head = get<1>(v_result);
break;
}
}
return make_tuple(IBasicRule::MatchResult::Success, temp_head);
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;
}
QString Rept::token_present() const
{
return u8"(" + this->rule_peer->token_present() + QString(u8"{%1, %2}").arg(min_match).arg(max_match) + u8")";
return u8"(" + this->rule_peer->token_present() + QString(u8"){%1, %2}").arg(min_match).arg(max_match);
}
Seqs::Seqs(const QList<shared_ptr<const IBasicRule>> mbrs) : mbrs_store(mbrs) {}
QList<shared_ptr<const IBasicRule>> Seqs::children() const { return mbrs_store; }
tuple<IBasicRule::MatchResult, shared_ptr<const IWordBase>>
Seqs::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, IBasicRule::ErrOccurs& fx_type) const {
auto temp_head = head;
ParseResult Seqs::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const {
ParseResult result_final;
auto temp_head = head;
bool straight_mark = fx_type == ErrDeals::None;
for (auto& r : mbrs_store) {
auto rule_present = r->token_present();
auto rst_gene = r->parse(rt_inst, temp_head, fx_type);
switch (get<0>(rst_gene)) {
case IBasicRule::MatchResult::Fail:
return make_tuple(IBasicRule::MatchResult::Part, temp_head);
case IBasicRule::MatchResult::Part:
return rst_gene;
case IBasicRule::MatchResult::Success:
temp_head = get<1>(rst_gene);
auto v_result = rst_gene.result_straight;
if(std::get<0>(v_result) == MatchResult::None)
v_result = rst_gene.result_repair;
switch (get<0>(v_result)) {
case MatchResult::Part:
if(straight_mark)
result_final.result_straight = v_result;
else
result_final.result_repair = v_result;
return result_final;
case MatchResult::Success:
temp_head = get<1>(v_result);
break;
default:
break;
}
}
return make_tuple(IBasicRule::MatchResult::Success, temp_head);
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;
}
QString Seqs::token_present() const
@ -156,55 +190,49 @@ QString Seqs::token_present() const
QString content;
for (auto& it : children())
content += it->token_present();
return QString(u8"(%1)").arg(content);
return content;
}
//tuple<IBasicRule::MatchResult, uint, shared_ptr<const IBasicRule>, shared_ptr<const Token>>
//tuple<MatchResult, uint, shared_ptr<const IBasicRule>, shared_ptr<const Token>>
Any::Any(const QList<shared_ptr<const IBasicRule>> mbrs) : mbrs_store(mbrs) {}
QList<shared_ptr<const IBasicRule>> Any::children() const { return mbrs_store; }
class words_span {
public:
int row_span, column_span;
words_span(int rspan, int cspan) :row_span(rspan), column_span(cspan) {}
bool operator>(const words_span& other) {
if (row_span > other.row_span)
return true;
if (row_span == other.row_span)
return column_span > other.column_span;
return false;
}
};
tuple<IBasicRule::MatchResult, shared_ptr<const IWordBase>>
Any::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, IBasicRule::ErrOccurs& fx_type) const {
tuple<shared_ptr<const IBasicRule>, uint64_t> temp_result = make_tuple(nullptr, 0);
ParseResult Any::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const {
auto rule_present = this->token_present();
for (auto& fork : mbrs_store) {
auto gen = fork->parse(rt_inst, head, fx_type);
switch (get<0>(gen)) {
// 遇到成功的直接返回解析结果
case IBasicRule::MatchResult::Success:
return gen;
case IBasicRule::MatchResult::Fail: {
if (!get<0>(temp_result))
temp_result = make_tuple(fork, 0);
}break;
case IBasicRule::MatchResult::Part: {
auto span = get<1>(gen)->position() - head->position();
if (span >= get<1>(temp_result))
temp_result = make_tuple(fork, span);
}
default:
break;
ParseResult result_final;
bool straight_mark = fx_type == ErrDeals::None;
switch (fx_type) {
case ErrDeals::None: {
for (auto& fork : mbrs_store) {
auto gen = fork->parse(rt_inst, head, fx_type);
switch (get<0>(gen.result_straight)) {
// 遇到成功的直接返回解析结果
case MatchResult::Success:
return gen;
case MatchResult::Part: {
auto span = get<1>(gen)->position() - head->position();
if (span >= get<1>(temp_result))
temp_result = make_tuple(fork, span);
}
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));
}
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(IBasicRule::MatchResult::Part, get<1>(temp));
}
QString Any::token_present() const
@ -213,7 +241,7 @@ QString Any::token_present() const
for (auto& it : children()) {
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);
}
@ -240,52 +268,41 @@ QList<shared_ptr<const IBasicRule>> ExprRule::children() const {
}
#include <ast_novel.h>
tuple<IBasicRule::MatchResult, shared_ptr<const IWordBase>>
ExprRule::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, IBasicRule::ErrOccurs& fx_type) const {
QList<IBasicRule::ErrOccurs> opts_list = {
IBasicRule::ErrOccurs::None, IBasicRule::ErrOccurs::Surplus, IBasicRule::ErrOccurs::Absence, IBasicRule::ErrOccurs::Replace };
tuple<MatchResult, shared_ptr<const IWordBase>>
ExprRule::parse(shared_ptr<IContext> rt_inst, shared_ptr<const IWordBase> head, ErrDeals& fx_type) const {
auto text_present = this->token_present();
shared_ptr<IExprInst> elm_ast = this->newEmptyInstance();
auto opt_current_itor = opts_list.cbegin();
tuple<IBasicRule::MatchResult, shared_ptr<const IWordBase>> ret_tuple;
do {
auto opt_val = *opt_current_itor;
shared_ptr<IExprInst> elm_ast = this->newEmptyInstance();
auto text_present = this->token_present();
rt_inst->pushExprRule(this->shared_from_this());
rt_inst->pushExprInst(elm_ast);
rt_inst->pushExprRule(this->shared_from_this());
rt_inst->pushExprInst(elm_ast);
ret_tuple = child_store->parse(rt_inst, head, opt_val);
auto tokens_decl = elm_ast->tokens();
switch (get<0>(ret_tuple)) {
case IBasicRule::MatchResult::Fail:
case IBasicRule::MatchResult::Part:
rt_inst->popExprInst();
rt_inst->popExprRule();
break;
case IBasicRule::MatchResult::Success: {
if (!dynamic_pointer_cast<example_novel::Document>(elm_ast) && opt_val == IBasicRule::ErrOccurs::None) {
auto start_pos = head->position();
rt_inst->clearErrors(rt_inst->currentFile(), start_pos);
}
rt_inst->popExprInst();
rt_inst->popExprRule();
if (rt_inst->currentExprInst()) {
rt_inst->currentExprInst()->addChild(elm_ast);
}
else {
rt_inst->appendDocInst(elm_ast);
}
}break;
default:
break;
auto ret_tuple = child_store->parse(rt_inst, head, fx_type);
switch (get<0>(ret_tuple)) {
case MatchResult::Success:
if (!dynamic_pointer_cast<example_novel::Document>(elm_ast) && fx_type == ErrDeals::None) {
rt_inst->clearErrors(rt_inst->currentFile(), head->position());
}
opt_current_itor++;
} while (fx_type != IBasicRule::ErrOccurs::None && opt_current_itor != opts_list.cend());
rt_inst->popExprInst();
rt_inst->popExprRule();
if (rt_inst->currentExprInst()) {
rt_inst->currentExprInst()->addChild(elm_ast);
}
else {
rt_inst->appendDocInst(elm_ast);
}
break;
case MatchResult::Part:
case MatchResult::Fail:
rt_inst->popExprInst();
rt_inst->popExprRule();
break;
default:
break;
}
return ret_tuple;
}

View File

@ -35,12 +35,12 @@ namespace lib_syntax {
public:
virtual ~IContext() = default;
virtual void setCurrentFile(const QString &path) = 0;
virtual void setCurrentFile(const QString& path) = 0;
virtual QString currentFile() const = 0;
virtual void appendParseErrors(const QString & file_path, int start, const QString &error_msg) = 0;
virtual void appendParseError(const QString& file_path, int start, const QString& error_msg) = 0;
virtual QStringList errors() const = 0;
virtual void clearErrors(const QString &file_path, int start) = 0;
virtual void clearErrors(const QString& file_path, int start) = 0;
virtual void appendDocInst(std::shared_ptr<ast_basic::IExprInst> inst) = 0;
virtual QList<std::shared_ptr<const ast_basic::IExprInst>> getDocInsts() const = 0;
@ -60,6 +60,33 @@ namespace lib_syntax {
virtual QList<std::shared_ptr<const IBasicRule>> currentExprRuleStack() const = 0;
};
/**
* @brief
*/
enum class MatchResult {
None, // 不适用
Success, // 符合匹配条件
Part, // 部分匹配
};
/**
* @brief
*/
enum class ErrDeals {
None, // 不修复
Surplus, // 多一个词
Absence, // 少一个词
Replace, // 错一个词
};
/**
* .
*/
struct ParseResult {
std::tuple<MatchResult, std::shared_ptr<const lib_token::IWordBase>> result_straight = std::make_tuple(MatchResult::None, nullptr);
std::tuple<MatchResult, std::shared_ptr<const lib_token::IWordBase>> result_repair = std::make_tuple(MatchResult::None, nullptr);
};
/**
* @brief
*/
@ -72,24 +99,6 @@ namespace lib_syntax {
*/
virtual QList<std::shared_ptr<const IBasicRule>> children() const = 0;
/**
* @brief
*/
enum class MatchResult {
Success, // 符合匹配条件
Part, // 部分匹配
Fail // 从第一个词起完全不匹配
};
/**
* @brief
*/
enum class ErrOccurs {
None, // 无
Replace, // 错一个词
Absence, // 少一个词
Surplus // 多一个词
};
/**
* @brief
@ -98,8 +107,7 @@ namespace lib_syntax {
* @param fx_type
* @return <,>
*/
virtual std::tuple<IBasicRule::MatchResult, std::shared_ptr<const lib_token::IWordBase>>
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrOccurs &fx_type) const = 0;
virtual ParseResult parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrDeals& fx_type) const = 0;
/**
*
@ -123,8 +131,7 @@ namespace lib_syntax {
// IBasicRule interface
public:
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
virtual std::tuple<IBasicRule::MatchResult, std::shared_ptr<const lib_token::IWordBase>>
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrOccurs &fx_type) const override;
virtual ParseResult parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrDeals& fx_type) const override;
virtual QString token_present() const override;
};
@ -143,8 +150,7 @@ namespace lib_syntax {
// IBasicRule interface
public:
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
virtual std::tuple<IBasicRule::MatchResult, std::shared_ptr<const lib_token::IWordBase>>
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrOccurs &fx_type) const override;
virtual ParseResult parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrDeals& fx_type) const override;
virtual QString token_present() const override;
};
@ -161,8 +167,7 @@ namespace lib_syntax {
// IBasicRule interface
public:
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
virtual std::tuple<IBasicRule::MatchResult, std::shared_ptr<const lib_token::IWordBase>>
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrOccurs &fx_type) const override;
virtual ParseResult parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrDeals& fx_type) const override;
virtual QString token_present() const override;
};
@ -180,8 +185,7 @@ namespace lib_syntax {
// IBasicRule interface
public:
virtual QList<std::shared_ptr<const IBasicRule>> children() const override;
virtual std::tuple<IBasicRule::MatchResult, std::shared_ptr<const lib_token::IWordBase>>
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrOccurs &fixed_type) const override;
virtual ParseResult parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrDeals& fx_type) const override;
virtual QString token_present() const override;
};
@ -204,8 +208,7 @@ namespace lib_syntax {
// IBasicRule interface
public:
virtual QList<std::shared_ptr<const lib_syntax::IBasicRule>> children() const override;
virtual std::tuple<IBasicRule::MatchResult, std::shared_ptr<const lib_token::IWordBase>>
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrOccurs &fx_type) const override;
virtual ParseResult parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head, ErrDeals& fx_type) const override;
virtual QString token_present() const override;
protected:
@ -223,7 +226,7 @@ namespace lib_syntax {
class ElementRule : public ExprRule {
public:
ElementRule(const QString& rule_name, int expr_mark)
:ExprRule(rule_name, expr_mark){}
:ExprRule(rule_name, expr_mark) {}
virtual std::shared_ptr<ast_basic::IExprInst> newEmptyInstance() const {
return std::dynamic_pointer_cast<ast_basic::IExprInst>(

View File

@ -12,6 +12,7 @@ auto leftb = std::make_shared<LeftBracket>(); // {
auto rightb = std::make_shared<RightBracket>(); // }
auto refers = std::make_shared<ReferMark>(); // @
auto declare = std::make_shared<DeclareSymbo>(); // #
auto split_mark = std::make_shared<Split>(); // &
auto rank_key = std::make_shared<Keywords>(u8"排序", 0xAEu); // 排序
auto story_key = std::make_shared<Keywords>(u8"故事", 0xAAu); // 故事
@ -19,9 +20,8 @@ auto numbers = std::make_shared<Numbers>(); // [0-9
auto frag_key = std::make_shared<Keywords>(u8"情节", 0xABu); // 情节
auto volume_key = std::make_shared<Keywords>(u8"分卷", 0xACu); // 分卷
auto article_key = std::make_shared<Keywords>(u8"章节", 0xADu); // 章节
auto split_mark = std::make_shared<Split>(); // &
auto vtext = std::make_shared<VTextSection>(); // ^([^\\{\\}\\n@&]+)
auto name_text = std::make_shared<NameSection>(); // ^([^:\\{\\}\\n@&][^\\{\\}\\n@&]*)
auto vtext = std::make_shared<VTextSection>(); // ^([^\\{\\}@&]+)
auto name_text = std::make_shared<NameSection>(); // ^([^\\{\\}@&]+)
@ -38,21 +38,21 @@ auto name_text = std::make_shared<NameSection>(); // ^
auto decl_comp = std::make_shared<const Any>(Rules{ MR(numbers), MR(vtext), MR(name_text), MR(split_mark) });
auto decl_comp = std::make_shared<const Any>(Rules{ MR(refers), MR(vtext), MR(split_mark) });
auto decl_expr = ElementRule<TextSection>(u8"decl_section", (int)NovelExprs::DESC_SECTION).reloadRule(
MultiR(decl_comp));
OptMulR(decl_comp));
auto fragment_decl = ElementRule<FragmentDefine>(u8"fragment_define", (int)NovelExprs::FRAG_DEFINES).reloadRule(
std::make_shared<const Seqs>(
Rules{ MR(leftb), MR(frag_key), MR(name_text) } <<
OptMulR(decl_expr) <<
decl_expr <<
MR(rightb)
));
auto fragment_refer = ElementRule<FragmentRefers>(u8"fragment_refer", (int)NovelExprs::FRAG_REFERS).reloadRule(
std::make_shared<const Seqs>(
Rules{ MR(leftb), MR(refers), MR(frag_key), MR(name_text), MR(split_mark), MR(name_text) } <<
OptMulR(decl_expr) <<
decl_expr <<
MR(rightb)
));
@ -87,7 +87,7 @@ auto document_define = ElementRule<Document>(u8"decls-doc", (int)NovelExprs::DOC
std::make_shared<const Seqs>(
Rules{
std::make_shared<const Rept>(rank_define, 0, 1),
MultiR(std::make_shared<const Any>(Rules{story_define, volume_decl}))
OptMulR(std::make_shared<const Any>(Rules{story_define, volume_decl}))
}
));

View File

@ -121,7 +121,7 @@ int VTextSection::typeMark() const
return 0x09000000;
}
QString VTextSection::regex() const { return u8"^([^\\{\\}\\n@&]+)"; }
QString VTextSection::regex() const { return u8"^([^\\{\\}@&]+)"; }
std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const IWordBase>>
VTextSection::analysis(std::shared_ptr<const IWordBase> content) const {
@ -160,7 +160,7 @@ int NameSection::typeMark() const
return 0x08000000;
}
QString NameSection::regex() const { return u8"^([^:\\{\\}\\n@&][^\\{\\}\\n@&]*)"; }
QString NameSection::regex() const { return u8"^([^\\{\\}@&]+)"; }
std::tuple<std::shared_ptr<const IToken>, std::shared_ptr<const IWordBase> > NameSection::analysis(std::shared_ptr<const IWordBase> content) const
{