| 1 |
#include "polsyntaxhighlighter.h" |
| 2 |
#include <QRegExp> |
| 3 |
#include <QTextCharFormat> |
| 4 |
#include <QDebug> |
| 5 |
|
| 6 |
using namespace xmpsolve; |
| 7 |
|
| 8 |
PolSyntaxHighlighter::PolSyntaxHighlighter(QObject *parent) : |
| 9 |
QSyntaxHighlighter(parent) |
| 10 |
{ |
| 11 |
} |
| 12 |
|
| 13 |
void |
| 14 |
PolSyntaxHighlighter::highlightBlock(const QString &text) |
| 15 |
{ |
| 16 |
QTextCharFormat commentFormat; |
| 17 |
commentFormat.setForeground(Qt::darkRed); |
| 18 |
|
| 19 |
QTextCharFormat statementFormat; |
| 20 |
statementFormat.setForeground(Qt::darkBlue); |
| 21 |
|
| 22 |
QRegExp commentRegexp("!.*"); |
| 23 |
int index = text.indexOf(commentRegexp); |
| 24 |
while (index >= 0) { |
| 25 |
int length = commentRegexp.matchedLength(); |
| 26 |
setFormat(index, length, commentFormat); |
| 27 |
index = text.indexOf(commentRegexp, index + length); |
| 28 |
} |
| 29 |
|
| 30 |
QRegExp assignmentRegExp("[^=]+\\s*=\\s*[^;]+\\s*;"); |
| 31 |
index = text.indexOf(assignmentRegExp); |
| 32 |
while (index >= 0) { |
| 33 |
int length = assignmentRegExp.matchedLength(); |
| 34 |
setFormat(index, length, statementFormat); |
| 35 |
index = text.indexOf(assignmentRegExp, index + length); |
| 36 |
} |
| 37 |
|
| 38 |
QRegExp statementRegexp(".+\\s*;"); |
| 39 |
index = text.indexOf(statementRegexp); |
| 40 |
while (index >= 0) { |
| 41 |
int length = statementRegexp.matchedLength(); |
| 42 |
setFormat(index, length, statementFormat); |
| 43 |
index = text.indexOf(statementRegexp, index + length); |
| 44 |
} |
| 45 |
} |