14 static int NOT_MULTILINE_COMMENT = 0;
15 static int MULTILINE_COMMENT = 1;
21 QSyntaxHighlighter(pc_text) {
22 SHighlightingRule sRule;
23 m_cKeywordFormat.setForeground(Qt::darkBlue);
24 m_cKeywordFormat.setFontWeight(QFont::Bold);
25 QStringList cKeywordPatterns;
26 cKeywordPatterns <<
"\\band\\b" <<
"\\bbreak\\b" <<
"\\bdo\\b" <<
"\\belse\\b" <<
"\\belseif\\b"
27 <<
"\\bend\\b" <<
"\\bfalse\\b" <<
"\\bfor\\b" <<
"\\bfunction\\b" <<
"\\bif\\b"
28 <<
"\\bin\\b" <<
"\\blocal\\b" <<
"\\bnil\\b" <<
"\\bnot\\b" <<
"\\bor\\b"
29 <<
"\\brepeat\\b" <<
"\\breturn\\b" <<
"\\bthen\\b" <<
"\\btrue\\b" <<
"\\buntil\\b" <<
"\\bwhile\\b";
30 foreach (
const QString& cPattern, cKeywordPatterns) {
31 sRule.Pattern = QRegularExpression(cPattern);
32 sRule.Format = m_cKeywordFormat;
33 m_vecHighlightingRules.append(sRule);
36 m_cQuotationFormat.setForeground(Qt::darkGreen);
37 sRule.Pattern = QRegularExpression(
"\".*\"");
38 sRule.Format = m_cQuotationFormat;
39 m_vecHighlightingRules.append(sRule);
41 m_cSingleLineCommentFormat.setForeground(Qt::darkGray);
42 m_cSingleLineCommentFormat.setFontItalic(
true);
43 sRule.Pattern = QRegularExpression(
"--[^[\n]*");
44 sRule.Format = m_cSingleLineCommentFormat;
45 m_vecHighlightingRules.append(sRule);
47 m_cMultiLineCommentFormat.setForeground(Qt::darkGray);
48 m_cMultiLineCommentFormat.setFontItalic(
true);
49 m_cCommentStartExpression = QRegularExpression(
"--\\[\\[");
50 m_cCommentEndExpression = QRegularExpression(
"\\]\\]");
60 foreach (
const SHighlightingRule& sRule, m_vecHighlightingRules) {
61 QRegularExpression cExpression(sRule.Pattern);
62 QRegularExpressionMatchIterator cMatchIt = cExpression.globalMatch(str_text);
63 while(cMatchIt.hasNext()) {
64 QRegularExpressionMatch cMatch = cMatchIt.next();
65 setFormat(cMatch.capturedStart(), cMatch.capturedLength(), sRule.Format);
71 setCurrentBlockState(NOT_MULTILINE_COMMENT);
73 if (previousBlockState() != MULTILINE_COMMENT) {
74 nStartIndex = str_text.indexOf(m_cCommentStartExpression);
76 while(nStartIndex >= 0) {
77 QRegularExpressionMatch cEndMatch;
78 int nEndIndex = str_text.indexOf(m_cCommentEndExpression, nStartIndex, &cEndMatch);
80 if (nEndIndex == -1) {
81 setCurrentBlockState(MULTILINE_COMMENT);
82 nCommentLength = str_text.length() - nStartIndex;
84 nCommentLength = nEndIndex - nStartIndex + cEndMatch.capturedLength();
86 setFormat(nStartIndex, nCommentLength, m_cMultiLineCommentFormat);
87 nStartIndex = str_text.indexOf(m_cCommentStartExpression, nStartIndex + nCommentLength);
The namespace containing all the ARGoS related code.
void highlightBlock(const QString &str_text)
CQTOpenGLLuaSyntaxHighlighter(QTextDocument *pc_text)