25 #include "moc_PythonSyntaxHighlighter.cpp"
30 keywords = QStringList() <<
"and" <<
"assert" <<
"break" <<
"class" <<
"continue" <<
"def" <<
31 "del" <<
"elif" <<
"else" <<
"except" <<
"exec" <<
"finally" <<
32 "for" <<
"from" <<
"global" <<
"if" <<
"import" <<
"in" <<
33 "is" <<
"lambda" <<
"not" <<
"or" <<
"pass" <<
"print" <<
34 "raise" <<
"return" <<
"try" <<
"while" <<
"yield" <<
35 "None" <<
"True" <<
"False";
39 "==" <<
"!=" <<
"<" <<
"<=" <<
">" <<
">=" <<
41 "\\+" <<
"-" <<
"\\*" <<
"/" <<
"//" <<
"%" <<
"\\*\\*" <<
43 "\\+=" <<
"-=" <<
"\\*=" <<
"/=" <<
"%=" <<
45 "\\^" <<
"\\|" <<
"&" <<
"~" <<
">>" <<
"<<";
47 braces = QStringList() <<
"{" <<
"}" <<
"\\(" <<
"\\)" <<
"\\[" <<
"]";
68 foreach(QString currKeyword,
keywords)
76 foreach(QString currBrace,
braces)
111 auto matches = currRule.
pattern.globalMatch(text);
112 while (matches.hasNext())
115 auto match = matches.next();
116 auto idx = match.capturedStart(currRule.
nth);
117 int length = match.captured(currRule.
nth).length();
118 setFormat(idx, length, currRule.
format);
122 setCurrentBlockState(0);
138 if (previousBlockState() == inState) {
144 auto match = delimiter.match(text);
145 start = match.capturedStart();
147 add = match.capturedLength();
153 auto match = delimiter.match(text,
static_cast<qsizetype
>(start) + add);
154 end = match.capturedStart();
157 length =
static_cast<qsizetype
>(end) - start + add + match.capturedLength();
158 setCurrentBlockState(0);
162 setCurrentBlockState(inState);
163 length = text.length() - start + add;
166 setFormat(start, length, style);
167 match = delimiter.match(text,
static_cast<qsizetype
>(start) + length);
168 start = match.capturedStart();
171 if (currentBlockState() == inState)
179 QTextCharFormat charFormat;
180 QColor color(colorName);
181 charFormat.setForeground(color);
182 if (style.contains(
"bold", Qt::CaseInsensitive))
183 charFormat.setFontWeight(QFont::Bold);
184 if (style.contains(
"italic", Qt::CaseInsensitive))
185 charFormat.setFontItalic(
true);
Container to describe a highlighting rule. Based on a regular expression, a relevant match # and the ...
QRegularExpression pattern
void highlightBlock(const QString &text)
QRegularExpression triDoubleQuote
const QTextCharFormat getTextCharFormat(const QString &colorName, const QString &style=QString())
QRegularExpression triSingleQuote
QHash< QString, QTextCharFormat > basicStyles
bool matchMultiline(const QString &text, const QRegularExpression &delimiter, const int inState, const QTextCharFormat &style)
Highlighst multi-line strings, returns true if after processing we are still within the multi-line se...
QList< HighlightingRule > rules