-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsyntaxrun.cpp
More file actions
65 lines (56 loc) · 2.2 KB
/
syntaxrun.cpp
File metadata and controls
65 lines (56 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "syntaxrun.h"
SyntaxRun::SyntaxRun(QString _spin, QString _path, QString _fileName, QString _ltl) : SpinRun(_spin, _path , _fileName, Syntax) {
path = _path;
fileName = _fileName;
ltl = _ltl;
errors = -1;
}
SyntaxRun::~SyntaxRun(){
process->deleteLater();
}
//TODO: Denne skal måske have en deletelater metode (destructor)
void SyntaxRun::start(){
process = new QProcess();
process->setWorkingDirectory(path);
connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(checkSyntax()));
connect(process, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(error()));
connect(process, SIGNAL(readyReadStandardError()), this, SLOT(error()));
setStatus("Checking syntax with spin -a");
tempPath = createTempPml();
process->start(spin,QStringList() << "-a" << "\""+filePath+"\"");
}
QString SyntaxRun::createTempPml(){
QFile::copy(path,path+".qspin");
QFile tempFile(path+".qspin");
if ( tempFile.open(QIODevice::Append | QIODevice::ReadWrite) )
{
QTextStream stream( &tempFile );
stream << "\n " + ltl << endl;
}
return path + QDir::separator() + fileName + ".qspin";
}
void SyntaxRun::checkSyntax(){
QString str = process->readAllStandardOutput();
QRegExp rxLine("spin: "+filePath+":(\\d+),");
QRegExp rxError("spin: "+filePath+":\\d+, Error:(\\D*)");
//QStringList lineNoList;
//QStringList errorList;
int pos = 0;
while ((pos = rxError.indexIn(str , (rxLine.indexIn(str, pos)) )) != -1) {
QString lineNo = rxLine.cap(1);
QString error = rxError.cap(1);
lineNoList << lineNo;
errorList << error;
pos += rxLine.matchedLength()+rxError.matchedLength();
}
errors = errorList.count();
QFile::remove(tempPath);
if (errors>0) {
setStatus(QString::number(errors)+" errors found");
emit hasErrors();
} else {
setStatus("No errors found :)");
emit noErrors();
}
emit finished(this);
}