改进解析过程
This commit is contained in:
parent
e8534447be
commit
7d14a5a207
|
@ -69,15 +69,16 @@ int main(int argc, char* argv[]) {
|
|||
if (files.size()) {
|
||||
try {
|
||||
auto parser = std::make_shared<NovelParser>();
|
||||
access_ptr = parser->parse(files);
|
||||
auto docs = parser->parse(files);
|
||||
|
||||
auto errors_list = std::dynamic_pointer_cast<const ast_gen::GlobalElement>(access_ptr->element())->errors();
|
||||
auto errors_list = parser->parserContext()->errors();
|
||||
if (errors_list.size()) {
|
||||
for (auto& err : errors_list) {
|
||||
qDebug().noquote() << err;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
access_ptr = parser->validsApply(docs);
|
||||
}
|
||||
catch (lib_syntax::SyntaxException* e) {
|
||||
qDebug().noquote() << e->message();
|
||||
|
|
|
@ -29,10 +29,14 @@ QString NovelParser::version() const
|
|||
return "1.0.0";
|
||||
}
|
||||
|
||||
std::shared_ptr<const ast_gen::ElementAccess> NovelParser::parse(const QFileInfoList source_list) const {
|
||||
QList<std::shared_ptr<const ast_basic::IExprInst>> forst_root;
|
||||
std::shared_ptr<lib_syntax::IContext> NovelParser::parserContext() const
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<const ast_basic::IExprInst>> NovelParser::parse(const QFileInfoList source_list) const {
|
||||
const_cast<NovelParser*>(this)->context = std::make_shared<ast_gen::GlobalElement>(u8"С˵");
|
||||
auto word_reader = std::make_shared<lib_token::WordReader>();
|
||||
auto context = std::make_shared<ast_gen::GlobalElement>(u8"С˵");
|
||||
|
||||
auto time_stamp = QTime::currentTime();
|
||||
for (auto& file : source_list) {
|
||||
|
@ -41,13 +45,17 @@ std::shared_ptr<const ast_gen::ElementAccess> NovelParser::parse(const QFileInfo
|
|||
this->syntax_defines->parse(context, words);
|
||||
}
|
||||
|
||||
forst_root = context->getDocInsts();
|
||||
QList<std::shared_ptr<const ast_basic::IExprInst>> forst_root = context->getDocInsts();
|
||||
auto current_stamp = QTime::currentTime();
|
||||
qDebug().noquote() << QString(u8"%词法解析+语法解析消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
|
||||
time_stamp = QTime::currentTime();
|
||||
return forst_root;
|
||||
}
|
||||
|
||||
std::shared_ptr<const ast_gen::ElementAccess> NovelParser::validsApply(QList<std::shared_ptr<const ast_basic::IExprInst>> forst_root) const {
|
||||
auto time_stamp = QTime::currentTime();
|
||||
QList<std::shared_ptr<ast_gen::SyntaxElement>> docs_node;
|
||||
for (auto &it : forst_root) {
|
||||
for (auto& it : forst_root) {
|
||||
auto xitem = std::dynamic_pointer_cast<const ast_gen::SyntaxElement>(it);
|
||||
docs_node.append(std::const_pointer_cast<ast_gen::SyntaxElement>(xitem));
|
||||
context->addChild(docs_node.last());
|
||||
|
@ -55,7 +63,7 @@ std::shared_ptr<const ast_gen::ElementAccess> NovelParser::parse(const QFileInfo
|
|||
|
||||
auto x_root = NovalSyntax::tidy(context, docs_node);
|
||||
auto novel_accesstree = std::make_shared<ast_gen::ElementAccess>(x_root);
|
||||
current_stamp = QTime::currentTime();
|
||||
auto current_stamp = QTime::currentTime();
|
||||
qDebug().noquote() << QString(u8"%程序结构重建消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp));
|
||||
|
||||
return analyzer_ref->validCheckWith(novel_accesstree);
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace example_novel {
|
|||
class NovelParser
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<ast_gen::GlobalElement> context = nullptr;
|
||||
std::shared_ptr<const lib_syntax::ExprRule> syntax_defines;
|
||||
QList<std::shared_ptr<const lib_parse::CheckProvider>> checker_list;
|
||||
std::shared_ptr<const lib_parse::Analyzer> analyzer_ref;
|
||||
|
@ -21,5 +22,7 @@ public:
|
|||
QList<std::shared_ptr<const example_novel::FragmentGraphHelper>> fragmentsSorted() const;
|
||||
|
||||
virtual QString version() const;
|
||||
std::shared_ptr<const ast_gen::ElementAccess> parse(const QFileInfoList souurce_list) const;
|
||||
std::shared_ptr<lib_syntax::IContext> parserContext() const;
|
||||
QList<std::shared_ptr<const ast_basic::IExprInst>> parse(const QFileInfoList souurce_list) const;
|
||||
std::shared_ptr<const ast_gen::ElementAccess> validsApply(QList<std::shared_ptr<const ast_basic::IExprInst>> docs_list) const;
|
||||
};
|
Loading…
Reference in New Issue