2 #include <QCXXHighlighter>
3 #include <QSyntaxStyle>
13 m_includePattern (QRegularExpression(R
"(^\s*#\s*include\s*([<"][^:?"<>\|]+[">]))")),
14 m_functionPattern (QRegularExpression(R"(\b([_a-zA-Z][_a-zA-Z0-9]*\s+)?((?:[_a-zA-Z][_a-zA-Z0-9]*\s*::\s*)*[_a-zA-Z][_a-zA-Z0-9]*)(?=\s*\())")),
15 m_defTypePattern (QRegularExpression(R"(\b([_a-zA-Z][_a-zA-Z0-9]*)\s+[_a-zA-Z][_a-zA-Z0-9]*\s*[;=])")),
16 m_commentStartPattern(QRegularExpression(R"(/\*)")),
17 m_commentEndPattern (QRegularExpression(R"(\*/)"))
19 Q_INIT_RESOURCE(qcodeeditor_resources);
20 QFile fl(":/languages/cpp.xml");
22 if (!fl.open(QIODevice::ReadOnly))
29 if (!language.isLoaded())
34 auto keys = language.keys();
35 for (
auto&& key : keys)
37 auto names = language.names(key);
38 for (
auto&& name : names)
40 m_highlightRules.append({
41 QRegularExpression(QString(R
"(\b%1\b)").arg(name)),
48 m_highlightRules.append({
49 QRegularExpression(R
"((?<=\b|\s|^)(?i)(?:(?:(?:(?:(?:\d+(?:'\d+)*)?\.(?:\d+(?:'\d+)*)(?:e[+-]?(?:\d+(?:'\d+)*))?)|(?:(?:\d+(?:'\d+)*)\.(?:e[+-]?(?:\d+(?:'\d+)*))?)|(?:(?:\d+(?:'\d+)*)(?:e[+-]?(?:\d+(?:'\d+)*)))|(?:0x(?:[0-9a-f]+(?:'[0-9a-f]+)*)?\.(?:[0-9a-f]+(?:'[0-9a-f]+)*)(?:p[+-]?(?:\d+(?:'\d+)*)))|(?:0x(?:[0-9a-f]+(?:'[0-9a-f]+)*)\.?(?:p[+-]?(?:\d+(?:'\d+)*))))[lf]?)|(?:(?:(?:[1-9]\d*(?:'\d+)*)|(?:0[0-7]*(?:'[0-7]+)*)|(?:0x[0-9a-f]+(?:'[0-9a-f]+)*)|(?:0b[01]+(?:'[01]+)*))(?:u?l{0,2}|l{0,2}u?)))(?=\b|\s|$))"),
54 m_highlightRules.append({
55 QRegularExpression(R
"("[^\n"]*")"),
60 m_highlightRules.append({
61 QRegularExpression(R
"(#[a-zA-Z_]+)"),
66 m_highlightRules.append({
67 QRegularExpression(R
"(//[^\n]*)"),
78 while (matchIterator.hasNext())
80 auto match = matchIterator.next();
83 match.capturedStart(),
84 match.capturedLength(),
89 match.capturedStart(1),
90 match.capturedLength(1),
99 while (matchIterator.hasNext())
101 auto match = matchIterator.next();
104 match.capturedStart(),
105 match.capturedLength(),
110 match.capturedStart(2),
111 match.capturedLength(2),
119 while (matchIterator.hasNext())
121 auto match = matchIterator.next();
124 match.capturedStart(1),
125 match.capturedLength(1),
133 auto matchIterator = rule.pattern.globalMatch(text);
135 while (matchIterator.hasNext())
137 auto match = matchIterator.next();
140 match.capturedStart(),
141 match.capturedLength(),
147 setCurrentBlockState(0);
150 if (previousBlockState() != 1)
155 while (startIndex >= 0)
159 int endIndex =
match.capturedStart();
160 int commentLength = 0;
164 setCurrentBlockState(1);
165 commentLength = text.length() - startIndex;
169 commentLength = endIndex - startIndex +
match.capturedLength();