-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.cpp
More file actions
executable file
·116 lines (91 loc) · 3.72 KB
/
Copy pathsyntax.cpp
File metadata and controls
executable file
·116 lines (91 loc) · 3.72 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "syntax.h"
Syntax::Syntax(QTextDocument *parent)
: QSyntaxHighlighter(parent)
{
HighlightingRule rule;
QTextCharFormat multiLineCommentFormat;
multiLineCommentFormat.setForeground(Qt::darkRed);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}01.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::darkGreen);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}02.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::darkYellow);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}03.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::darkBlue);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}04.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::darkMagenta);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}05.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::darkCyan);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}06.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::lightGray);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}07.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::darkGray);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}08.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::red);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}09.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::green);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}10.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::yellow);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}11.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::blue);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}12.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::magenta);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}13.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::cyan);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}14.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::white);
rule.pattern = QRegExp("\\$[c,C][0-9]{2,2}15.*");
rule.format = multiLineCommentFormat;
highlightingRules.append(rule);
}
void Syntax::highlightBlock(const QString &text)
{
setCurrentBlockState(0);
QRegExp commentEndExpression("\\$[c,C][0-9]{4,4}");
foreach (HighlightingRule rule, highlightingRules) {
rule.pattern.setMinimal(true);
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = text.indexOf(rule.pattern);
while (startIndex >= 0) {
int endIndex = text.indexOf(commentEndExpression, startIndex+1);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex + commentEndExpression.matchedLength() - 6;
setCurrentBlockState(0);
}
setFormat(startIndex, commentLength, rule.format);
startIndex = text.indexOf(rule.pattern, startIndex + commentLength);
}
}
}