2 #include <QLuaHighlighter>
3 #include <QSyntaxStyle>
13 m_highlightBlockRules(),
14 m_requirePattern(QRegularExpression(R
"(require\s*([("'][a-zA-Z0-9*._]+['")]))")),
15 m_functionPattern(QRegularExpression(R"(\b([A-Za-z0-9_]+(?:\s+|::))*([A-Za-z0-9_]+)(?=\())")),
16 m_defTypePattern(QRegularExpression(R"(\b([A-Za-z0-9_]+)\s+[A-Za-z]{1}[A-Za-z0-9_]+\s*[=])"))
18 Q_INIT_RESOURCE(qcodeeditor_resources);
19 QFile fl(":/languages/lua.xml");
21 if (!fl.open(QIODevice::ReadOnly))
33 auto keys = language.
keys();
34 for (
auto&& key : keys)
36 auto names = language.
names(key);
37 for (
auto&& name : names)
40 QRegularExpression(QString(R
"(\b\s{0,1}%1\s{0,1}\b)").arg(name)),
48 QRegularExpression(R
"(\b(0b|0x){0,1}[\d.']+\b)"),
54 QRegularExpression(R
"(["'][^\n"]*["'])"),
60 QRegularExpression(R
"(#\![a-zA-Z_]+)"),
66 QRegularExpression(R
"(--[^\n]*)"),
72 QRegularExpression(R
"(--\[\[)"),
73 QRegularExpression(R"(--\]\])"),
79 QRegularExpression(R
"(\[\[)"),
80 QRegularExpression(R"(\]\])"),
90 while (matchIterator.hasNext())
92 auto match = matchIterator.next();
95 match.capturedStart(),
96 match.capturedLength(),
101 match.capturedStart(1),
102 match.capturedLength(1),
110 while (matchIterator.hasNext())
112 auto match = matchIterator.next();
115 match.capturedStart(),
116 match.capturedLength(),
121 match.capturedStart(2),
122 match.capturedLength(2),
130 while (matchIterator.hasNext())
132 auto match = matchIterator.next();
135 match.capturedStart(1),
136 match.capturedLength(1),
144 auto matchIterator = rule.pattern.globalMatch(text);
146 while (matchIterator.hasNext())
148 auto match = matchIterator.next();
151 match.capturedStart(),
152 match.capturedLength(),
158 setCurrentBlockState(0);
160 int highlightRuleId = previousBlockState();
164 if (startIndex >= 0) {
165 highlightRuleId = i + 1;
171 while (startIndex >= 0)
174 auto match = blockRules.endPattern.match(text, startIndex);
176 int endIndex =
match.capturedStart();
181 setCurrentBlockState(highlightRuleId);
182 matchLength =
text.length() - startIndex;
186 matchLength = endIndex - startIndex +
match.capturedLength();
194 startIndex =
text.indexOf(blockRules.startPattern, startIndex + matchLength);