WsParser_VS/CoreTest/main.cpp

45 lines
1.4 KiB
C++

#include <QtCore/QCoreApplication>
#include <libwords.h>
#include <qdebug.h>
#include <QFile>
#include <libsyntax.h>
#include <ast_gen.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);
lib_words::WordReader reader;
auto vwords = reader.wordsFrom(tt, "D:\\Projects\\Cpp\\WsNovelParser\\CoreTest\\syntax_example.txt");
auto words = vwords;
while (words) {
qDebug() << words->content();
words = words->nextWord();
}
ast_gen::SyntaxParser parser(example_novel::NovalSyntax::getSyntaxTree());
auto rst = parser.parse(vwords);
for (auto one : rst) {
qDebug() << "===================================================";
QList<QString> words_list;
auto vtoken = one->currentToken();
while (vtoken) {
if(vtoken->defines())
words_list.prepend(vtoken->content());
vtoken = vtoken->prevToken();
}
qDebug() << QString("Row:%1,Col:%2,Position:%3,ErrorCount:%4,Errors:")
.arg(one->currentToken()->row()).arg(one->currentToken()->column()).arg(one->currentToken()->position()).arg(one->exprsErrorCount())
<< one->totalErrors();
qDebug() << words_list;
}
return a.exec();
}