00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <QtCore/QString>
00039
00040 #include "StGeomHighlighter.h"
00041
00043 StGeomHighlighter::StGeomHighlighter(QTextDocument *parent)
00044 : QSyntaxHighlighter(parent)
00045 {
00046 HighlightingRule rule;
00047
00048 keywordFormat.setForeground(Qt::darkBlue);
00049 keywordFormat.setFontWeight(QFont::Bold);
00050 QStringList keywordPatterns=QString(Keywords()).split(" ");
00051 for (int i = 0; i < keywordPatterns.size(); ++i) {
00052 keywordPatterns[i] = QString("\\b%1\\b").arg(keywordPatterns[i]);
00053 }
00054 foreach (QString pattern, keywordPatterns) {
00055 rule.pattern = QRegExp(pattern,Qt::CaseInsensitive);
00056 rule.format = keywordFormat;
00057 highlightingRules.append(rule);
00059 }
00061
00063 classFormat.setFontWeight(QFont::Bold);
00064 classFormat.setForeground(Qt::darkMagenta);
00065 rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
00066 rule.format = classFormat;
00067 highlightingRules.append(rule);
00069
00071 singleLineCommentFormat.setForeground(Qt::red);
00072 rule.pattern = QRegExp("^[\\*Cc!]+.*$");
00073 rule.format = singleLineCommentFormat;
00074 highlightingRules.append(rule);
00075
00076 multiLineCommentFormat.setForeground(Qt::red);
00078
00080 quotationFormat.setForeground(Qt::darkGreen);
00081 rule.pattern = QRegExp("\".*\"");
00082 rule.format = quotationFormat;
00083 highlightingRules.append(rule);
00085
00087 functionFormat.setFontItalic(true);
00088 functionFormat.setForeground(Qt::blue);
00089 rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
00090 rule.format = functionFormat;
00091 highlightingRules.append(rule);
00093
00095 commentStartExpression = QRegExp("/\\*");
00096 commentEndExpression = QRegExp("\\*/");
00097 }
00099
00101 void StGeomHighlighter::highlightBlock(const QString &text)
00102 {
00103 foreach (HighlightingRule rule, highlightingRules) {
00104 QRegExp expression(rule.pattern);
00105 int index = text.indexOf(expression);
00106 while (index >= 0) {
00107 int length = expression.matchedLength();
00108 setFormat(index, length, rule.format);
00109 index = text.indexOf(expression, index + length);
00110 }
00111 }
00113 setCurrentBlockState(0);
00115
00117 int startIndex = 0;
00118 if (previousBlockState() != 1)
00119 startIndex = text.indexOf(commentStartExpression);
00120
00122 while (startIndex >= 0) {
00124 int endIndex = text.indexOf(commentEndExpression, startIndex);
00125 int commentLength;
00126 if (endIndex == -1) {
00127 setCurrentBlockState(1);
00128 commentLength = text.length() - startIndex;
00129 } else {
00130 commentLength = endIndex - startIndex
00131 + commentEndExpression.matchedLength();
00132 }
00133 setFormat(startIndex, commentLength, multiLineCommentFormat);
00134 startIndex = text.indexOf(commentStartExpression,
00135 startIndex + commentLength);
00136 }
00137 }
00139
00140
00141 const char *StGeomHighlighter::Keywords()
00142 {
00143 return
00144 "access action advance allocatable allocate apostrophe assign "
00145 "assignment associate asynchronous backspace bind blank blockdata "
00146 "call case character class close common complex contains continue "
00147 "cycle data deallocate decimal delim default dimension direct do "
00148 "dowhile double doubleprecision else elseif elsewhere encoding "
00149 "end endassociate endblockdata enddo endfile endforall "
00150 "endfunction endif endinterface endmodule endprogram endselect "
00151 "endsubroutine endtype endwhere entry eor equivalence err errmsg "
00152 "exist exit external file flush fmt forall form format formatted "
00153 "function go goto id if implicit in include inout integer inquire "
00154 "intent interface intrinsic iomsg iolength iostat kind len "
00155 "logical module name named namelist nextrec nml none nullify "
00156 "number only open opened operator optional out pad parameter pass "
00157 "pause pending pointer pos position precision print private "
00158 "program protected public quote read readwrite real rec recl "
00159 "recursive result return rewind save select selectcase selecttype "
00160 "sequential sign size stat status stop stream subroutine target "
00161 "then to type unformatted unit use value volatile wait where "
00162 "while write "
00163 "Block Component Content Create Fill endFill Material Medium Mixture Attribute "
00164 "Module Shape Structure EndBlock and or not";
00165 }
00166