7 :
QSyntaxHighlighter(parent), mMultiLineCommentDelimiter(
"('''|\"\"\")"), mTrippleSingleQuote(
"'''"), mTrippleDoubleQuote(
"\"\"\"")
31 HighlightingRule rule;
33 rule.mPattern =
QRegularExpression(
"\\b(and|as|assert|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|"
34 "nonlocal|not|or|pass|raise|return|try|while|with|yield|False|None|True)\\b");
35 rule.mPattern.optimize();
37 mHighlightingRules.
append(rule);
39 rule.mPattern =
QRegularExpression(
"=|==|!=|<|<=|>|>=|\\+|-|\\*|/|//|%|\\*\\*|\\+=|-=|\\*=|/=|%=|\\^|\\||&|~|>>|<<");
40 rule.mPattern.optimize();
42 mHighlightingRules.
append(rule);
45 rule.mPattern.optimize();
47 mHighlightingRules.
append(rule);
50 rule.mPattern.optimize();
52 mHighlightingRules.
append(rule);
55 rule.mPattern.optimize();
57 mHighlightingRules.
append(rule);
60 rule.mPattern.optimize();
62 mHighlightingRules.
append(rule);
64 rule.mPattern =
QRegularExpression(
"(\\b([1-9][0-9]*|0)[.]?[0-9]*[eE][+-]?[0-9]+[jJ]?\\b)|"
65 "(\\b([1-9][0-9]*|0)\\.[0-9]*[jJ]?)|"
66 "(\\b0[xX][0-9A-Fa-f]+[lL]?\\b)|"
67 "(\\b0[oO][0-7]+[lL]?\\b)|"
68 "(\\b([1-9][0-9]*|0)[lLjJ]?\\b)");
70 rule.mPattern.optimize();
72 mHighlightingRules.
append(rule);
75 rule.mPattern.optimize();
77 mHighlightingRules.
append(rule);
82 for (
const HighlightingRule& rule : mHighlightingRules)
98 int current_index = 0;
102 current_index = closeMultilineComment(text, mTrippleSingleQuote);
104 if (current_index < 0)
113 current_index = closeMultilineComment(text, mTrippleDoubleQuote);
115 if (current_index < 0)
132 QChar comment_type = text.
at(comment_start_index);
134 if (comment_type ==
'\'')
139 if (single_match_index < 0)
148 match = mMultiLineCommentDelimiter.
match(text, single_match_index + 3);
156 if (double_match_index < 0)
165 match = mMultiLineCommentDelimiter.
match(text, double_match_index + 3);
173 int PythonSyntaxHighlighter::closeMultilineComment(
const QString& text,
const QRegularExpression& delimiter,
const int offset)
static PythonQssAdapter * instance()
QTextCharFormat mBraceFormat
QTextCharFormat mNumberFormat
QTextCharFormat mSingleQuotedStringFormat
QTextCharFormat mCommentFormat
QTextCharFormat mDoubleQuotedStringFormat
QTextCharFormat mKeywordFormat
QTextCharFormat mOperatorFormat
QTextCharFormat mSelfFormat
PythonSyntaxHighlighter(QTextDocument *parent=nullptr)
void highlightBlock(const QString &text) override
QRegularExpressionMatch match(const QString &subject, int offset, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions) const const
int capturedEnd(int nth) const const
int capturedLength(int nth) const const
int capturedStart(int nth) const const
bool hasMatch() const const
bool hasNext() const const
QRegularExpressionMatch next()
const QChar at(int position) const const
int previousBlockState() const const
void setCurrentBlockState(int newState)
void append(const T &value)