42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#include <QtCore/QCoreApplication>
|
|
#include <libwords.h>
|
|
#include <qdebug.h>
|
|
#include <QFile>
|
|
#include <libsyntax.h>
|
|
#include <ast_gen.h>
|
|
#include <ast_novel.h>
|
|
#include <syntax_novel.h>
|
|
|
|
int main(int argc, char* argv[]) {
|
|
QCoreApplication a(argc, argv);
|
|
|
|
|
|
QFile in("D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
|
|
in.open(QIODevice::ReadOnly | QIODevice::Text);
|
|
QTextStream tt(&in);
|
|
tt.setCodec("UTF-8");
|
|
lib_words::WordReader reader;
|
|
auto vwords = reader.wordsFrom(tt, "D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
|
|
|
|
ast_gen::SyntaxParser parser(example_novel::NovalSyntax::getSyntaxTree());
|
|
auto rst = parser.parse(vwords);
|
|
|
|
if (rst.first()->totalErrorCount()) {
|
|
int err_count = 0;
|
|
auto pos_mark = rst.first()->token()->position();
|
|
for (auto item : rst)
|
|
if (item->token()->position() == pos_mark)
|
|
for (auto line : item->totalErrors()){
|
|
err_count++;
|
|
qDebug().noquote() << line;
|
|
}
|
|
qDebug() << err_count << "===========finished==========================";
|
|
}
|
|
else {
|
|
auto prag_root = std::make_shared<example_novel::NGlobalElement>("HelloWorld!");
|
|
auto structx = parser.getAst(rst.first(), prag_root);
|
|
parser.astPresent(structx);
|
|
}
|
|
return a.exec();
|
|
}
|