2 #include <QPythonHighlighter> 4 #include <QSyntaxStyle> 13 m_highlightBlockRules(),
14 m_includePattern (QRegularExpression(R
"(import \w+)")), 15 m_functionPattern (QRegularExpression(R"(\b([A-Za-z0-9_]+(?:\.))*([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/python.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%1\b)").arg(name)), 51 QRegularExpression(R
"(\b(0b|0x){0,1}[\d.']+\b)"), 57 QRegularExpression(R
"("[^\n"]*")"), 61 QRegularExpression(R
"('[^\n"]*')"), 67 QRegularExpression(
"#[^\n]*"),
73 QRegularExpression(
"(''')"),
74 QRegularExpression(
"(''')"),
78 QRegularExpression(
"(\"\"\")"),
79 QRegularExpression(
"(\"\"\")"),
90 while (matchIterator.hasNext())
92 auto match = matchIterator.next();
95 match.capturedStart(),
96 match.capturedLength(),
101 match.capturedStart(2),
102 match.capturedLength(2),
110 auto matchIterator = rule.pattern.globalMatch(text);
112 while (matchIterator.hasNext())
114 auto match = matchIterator.next();
117 match.capturedStart(),
118 match.capturedLength(),
124 setCurrentBlockState(0);
126 int highlightRuleId = previousBlockState();
131 if (startIndex >= 0) {
132 highlightRuleId = i + 1;
138 while (startIndex >= 0)
141 auto match = blockRules.endPattern.match(text, startIndex+1);
143 int endIndex =
match.capturedStart();
148 setCurrentBlockState(highlightRuleId);
149 matchLength = text.length() - startIndex;
153 matchLength = endIndex - startIndex +
match.capturedLength();
161 startIndex = text.indexOf(blockRules.startPattern, startIndex + matchLength);
QVector< QHighlightRule > m_highlightRules
QSyntaxStyle * syntaxStyle() const
Method for getting syntax style.
bool isLoaded() const
Method for getting is object loaded.
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
QStringList keys()
Method for getting available keys.
Class, that descrubes highlighter with syntax style.
QVector< QHighlightBlockRule > m_highlightBlockRules
QPythonHighlighter(QTextDocument *document=nullptr)
Constructor.
QTextCharFormat getFormat(QString name) const
Method for getting format for property name.
QRegularExpression m_functionPattern
void highlightBlock(const QString &text) override
static const char * match(MatchState *ms, const char *s, const char *p)
QStringList names(const QString &key)
Method for getting names from key.