ARGoS 3
A parallel, multi-engine simulator for swarm robotics
qtopengl_lua_syntax_highlighter.cpp
Go to the documentation of this file.
1
8
9namespace argos {
10
11 /****************************************/
12 /****************************************/
13
14 static int NOT_MULTILINE_COMMENT = 0;
15 static int MULTILINE_COMMENT = 1;
16
17 /****************************************/
18 /****************************************/
19
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);
34 }
35
36 m_cQuotationFormat.setForeground(Qt::darkGreen);
37 sRule.Pattern = QRegularExpression("\".*\"");
38 sRule.Format = m_cQuotationFormat;
39 m_vecHighlightingRules.append(sRule);
40
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);
46
47 m_cMultiLineCommentFormat.setForeground(Qt::darkGray);
48 m_cMultiLineCommentFormat.setFontItalic(true);
49 m_cCommentStartExpression = QRegularExpression("--\\[\\[");
50 m_cCommentEndExpression = QRegularExpression("\\]\\]");
51 }
52
53 /****************************************/
54 /****************************************/
55
56 void CQTOpenGLLuaSyntaxHighlighter::highlightBlock(const QString& str_text) {
57 /*
58 * Apply normal rules
59 */
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);
66 }
67 }
68 /*
69 * Apply multi-line comment rules
70 */
71 setCurrentBlockState(NOT_MULTILINE_COMMENT);
72 int nStartIndex = 0;
73 if (previousBlockState() != MULTILINE_COMMENT) {
74 nStartIndex = str_text.indexOf(m_cCommentStartExpression);
75 }
76 while(nStartIndex >= 0) {
77 QRegularExpressionMatch cEndMatch;
78 int nEndIndex = str_text.indexOf(m_cCommentEndExpression, nStartIndex, &cEndMatch);
79 int nCommentLength;
80 if (nEndIndex == -1) {
81 setCurrentBlockState(MULTILINE_COMMENT);
82 nCommentLength = str_text.length() - nStartIndex;
83 } else {
84 nCommentLength = nEndIndex - nStartIndex + cEndMatch.capturedLength();
85 }
86 setFormat(nStartIndex, nCommentLength, m_cMultiLineCommentFormat);
87 nStartIndex = str_text.indexOf(m_cCommentStartExpression, nStartIndex + nCommentLength);
88 }
89 }
90
91 /****************************************/
92 /****************************************/
93
94}
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12