修正了text-section解析
This commit is contained in:
parent
4ec73ffe6b
commit
da598a5ba6
|
@ -119,6 +119,7 @@ int main(int argc, char* argv[]) {
|
|||
std::cout << "nsc(WsNovelStoryCompiler:故事线编译器)" << std::endl;
|
||||
std::cout << "版本:V1.0.0" << std::endl;
|
||||
std::cout << "nsc --path path-to-dir --dest path-to-output [--html]" << std::endl;
|
||||
std::cout << "nsc --help" << std::endl;
|
||||
}break;
|
||||
}
|
||||
//return a.exec();
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace example_novel
|
|||
virtual bool isAnonymous() const override;
|
||||
virtual QString signature() const override;
|
||||
virtual void cacheLoad() override;
|
||||
|
||||
|
||||
private:
|
||||
QString name_store;
|
||||
};
|
||||
|
@ -166,3 +166,76 @@ namespace example_novel
|
|||
void cacheLoad() override;
|
||||
};
|
||||
}
|
||||
|
||||
namespace lib_syntax {
|
||||
template<> class ElementRule<example_novel::TextSection> : public ExprRule {
|
||||
public:
|
||||
ElementRule<example_novel::TextSection>(const QString& rule_name, int expr_mark)
|
||||
:ExprRule(rule_name, expr_mark) {}
|
||||
|
||||
// ͨ¹ý ExprRule ¼Ì³Ð
|
||||
virtual std::shared_ptr<ast_basic::IExprInst> newEmptyInstance() const {
|
||||
return std::dynamic_pointer_cast<ast_basic::IExprInst>(
|
||||
std::make_shared<example_novel::TextSection>(this->shared_from_this()));
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<ExprRule> makeCopy() const {
|
||||
return std::make_shared<ElementRule<example_novel::TextSection>>(name(), typeMark());
|
||||
}
|
||||
|
||||
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 {
|
||||
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);
|
||||
auto tokens_decl = elm_ast->tokens();
|
||||
|
||||
switch (std::get<0>(rstg)) {
|
||||
case IBasicRule::MatchResult::Fail:
|
||||
case IBasicRule::MatchResult::Part:
|
||||
rt_inst->popExprInst();
|
||||
rt_inst->popExprRule();
|
||||
break;
|
||||
case IBasicRule::MatchResult::Success: {
|
||||
if (!std::dynamic_pointer_cast<example_novel::Document>(elm_ast)) {
|
||||
auto start_pos = tokens_decl.first()->position();
|
||||
rt_inst->clearErrors(rt_inst->currentFile(), start_pos);
|
||||
}
|
||||
|
||||
rt_inst->popExprInst();
|
||||
rt_inst->popExprRule();
|
||||
while (tokens_decl.size()) {
|
||||
auto text_paragraph = this->newEmptyInstance();
|
||||
int row_n = tokens_decl.first()->row();
|
||||
|
||||
for (int idx = 0; idx < tokens_decl.size(); ++idx) {
|
||||
auto target_token = tokens_decl.at(idx);
|
||||
if (target_token->row() == row_n) {
|
||||
text_paragraph->addToken(target_token);
|
||||
tokens_decl.removeAt(idx--);
|
||||
}
|
||||
}
|
||||
|
||||
if (rt_inst->currentExprInst()) {
|
||||
rt_inst->currentExprInst()->addChild(text_paragraph);
|
||||
}
|
||||
else {
|
||||
rt_inst->appendDocInst(text_paragraph);
|
||||
}
|
||||
}
|
||||
|
||||
}break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return rstg;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -197,8 +197,10 @@ namespace lib_syntax {
|
|||
parse(std::shared_ptr<IContext> rt_inst, std::shared_ptr<const lib_token::IWordBase> head) const override;
|
||||
virtual QString token_present() const override;
|
||||
|
||||
private:
|
||||
protected:
|
||||
std::shared_ptr<const lib_syntax::IBasicRule> child_store;
|
||||
|
||||
private:
|
||||
QString name_store;
|
||||
int mark_store;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue