| 1 | // QCodeEditorcxx . . $ `<file>/src/internal/QPythonHighlighter.cpp`/ |
| 2 | #include <QPythonHighlighter>cxx . . $ `<file>/include/QPythonHighlighter`/ |
| 3 | #include <QLanguage>cxx . . $ `<file>/include/QLanguage`/ |
| 4 | #include <QSyntaxStyle>cxx . . $ `<file>/include/QSyntaxStyle`/ |
| 5 | |
| 6 | // Qt |
| 7 | #include <QFile> |
| 8 | #include <QDebug> |
| 9 | |
| 10 | QPythonHighlightercxx . . $ QPythonHighlighter#::QPythonHighlightercxx . . $ QPythonHighlighter#QPythonHighlighter(68d7deb16251beb9).(QTextDocumentcxx . . $ QTextDocument#* document) : |
| 11 | QStyleSyntaxHighlightercxx . . $ QStyleSyntaxHighlighter#(document), |
| 12 | m_highlightRulescxx . . $ QPythonHighlighter#m_highlightRules. (), |
| 13 | m_highlightBlockRulescxx . . $ QPythonHighlighter#m_highlightBlockRules.(), |
| 14 | m_includePatterncxx . . $ QPythonHighlighter#m_includePattern. (QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).(R"(import \w+)"cxx . . $ QString#QString(85c52e162fed56f9).)), |
| 15 | m_functionPatterncxx . . $ QPythonHighlighter#m_functionPattern. (QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).(R"(\b([A-Za-z0-9_]+(?:\.))*([A-Za-z0-9_]+)(?=\())"cxx . . $ QString#QString(85c52e162fed56f9).)), |
| 16 | m_defTypePatterncxx . . $ QPythonHighlighter#m_defTypePattern. (QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).(R"(\b([A-Za-z0-9_]+)\s+[A-Za-z]{1}[A-Za-z0-9_]+\s*[;=])"cxx . . $ QString#QString(85c52e162fed56f9).)) |
| 17 | { |
| 18 | Q_INIT_RESOURCEcxx . . $ `<external>/15045578679651060896/qglobal.h:469:9`!(qcodeeditor_resources); |
| 19 | QFilecxx . . $ QFile# flcxx . . $ QFile#QFile(3520e46b33348bf6).(":/languages/python.xml"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 20 | |
| 21 | if (!fl.opencxx . . $ QFile#open(dca164408be960c8).(QIODevicecxx . . $ QFlags#QFlags(9b289cee16747614).::ReadOnlycxx . . $ QIODevice#ReadOnly.)) |
| 22 | { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | QLanguagecxx . . $ QLanguage# languagecxx . . $ QLanguage#QLanguage(775d8a0db95c3304).(&fl); |
| 27 | |
| 28 | if (!language.isLoadedcxx . . $ QLanguage#isLoaded(50ce9a9e25b4a850).()) |
| 29 | { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | auto keys = language.keyscxx . . $ QLanguage#keys(669a05bc42dd57cc).(); |
| 34 | for (auto&& key : keys) |
| 35 | { |
| 36 | auto names = language.namescxx . . $ QLanguage#names(c46ca66a5ac9bada).(key); |
| 37 | for (auto&& name : names) |
| 38 | { |
| 39 | m_highlightRulescxx . . $ QPythonHighlighter#m_highlightRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightRule#QHighlightRule(5448daaee29b46b8). |
| 40 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).(QStringcxx . . $ QString#QString(85c52e162fed56f9).(R"(\b%1\b)").argcxx . . $ QString#arg(bc823072288cbbb5).(name)), |
| 41 | keycxx . . $ QString#QString(3520e46b33348bf6). |
| 42 | }); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // Following rules has higher priority to display |
| 47 | // than language specific keys |
| 48 | // So they must be applied at last. |
| 49 | // Numbers |
| 50 | m_highlightRulescxx . . $ QPythonHighlighter#m_highlightRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightRule#QHighlightRule(5448daaee29b46b8). |
| 51 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).(R"(\b(0b|0x){0,1}[\d.']+\b)"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 52 | "Number"cxx . . $ QString#QString(e1217c004a86c950). |
| 53 | }); |
| 54 | |
| 55 | // Strings |
| 56 | m_highlightRulescxx . . $ QPythonHighlighter#m_highlightRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightRule#QHighlightRule(5448daaee29b46b8). |
| 57 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).(R"("[^\n"]*")"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 58 | "String"cxx . . $ QString#QString(e1217c004a86c950). |
| 59 | }); |
| 60 | m_highlightRulescxx . . $ QPythonHighlighter#m_highlightRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightRule#QHighlightRule(5448daaee29b46b8). |
| 61 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).(R"('[^\n"]*')"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 62 | "String"cxx . . $ QString#QString(e1217c004a86c950). |
| 63 | }); |
| 64 | |
| 65 | // Single line comment |
| 66 | m_highlightRulescxx . . $ QPythonHighlighter#m_highlightRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightRule#QHighlightRule(5448daaee29b46b8). |
| 67 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).("#[^\n]*"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 68 | "Comment"cxx . . $ QString#QString(e1217c004a86c950). |
| 69 | }); |
| 70 | |
| 71 | // Multiline string |
| 72 | m_highlightBlockRulescxx . . $ QPythonHighlighter#m_highlightBlockRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightBlockRule#QHighlightBlockRule(199de7460b27bbcd). |
| 73 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).("(''')"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 74 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).("(''')"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 75 | "String"cxx . . $ QString#QString(e1217c004a86c950). |
| 76 | }); |
| 77 | m_highlightBlockRulescxx . . $ QPythonHighlighter#m_highlightBlockRules..appendcxx . . $ QVector#append(fe7a8a4d1eddb70).({cxx . . $ QHighlightBlockRule#QHighlightBlockRule(199de7460b27bbcd). |
| 78 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).("(\"\"\")"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 79 | QRegularExpressioncxx . . $ QRegularExpression#QRegularExpression(66445c245be5e58d).("(\"\"\")"cxx . . $ QString#QString(85c52e162fed56f9).), |
| 80 | "String"cxx . . $ QString#QString(e1217c004a86c950). |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | void QPythonHighlightercxx . . $ QPythonHighlighter#::highlightBlockcxx . . $ QPythonHighlighter#highlightBlock(3520e46b33348bf6).(const QStringcxx . . $ QString#& text) |
| 85 | { |
| 86 | // Checking for function |
| 87 | { |
| 88 | auto matchIterator = m_functionPatterncxx . . $ QRegularExpressionMatchIterator#QRegularExpressionMatchIterator(42df41e057175116)..globalMatchcxx . . $ QRegularExpression#globalMatch(72f8b242d28bebc1).(text); |
| 89 | |
| 90 | while (matchIterator.hasNextcxx . . $ QRegularExpressionMatchIterator#hasNext(50ce9a9e25b4a850).()) |
| 91 | { |
| 92 | auto match = matchIteratorcxx . . $ QRegularExpressionMatch#QRegularExpressionMatch(4c7bd13906b2250d)..nextcxx . . $ QRegularExpressionMatchIterator#next(5870644aafa115db).(); |
| 93 | |
| 94 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 95 | match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(), |
| 96 | match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(), |
| 97 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Type"cxx . . $ QString#QString(e1217c004a86c950).) |
| 98 | ); |
| 99 | |
| 100 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 101 | match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(2), |
| 102 | match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(2), |
| 103 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).("Function"cxx . . $ QString#QString(e1217c004a86c950).) |
| 104 | ); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | for (auto& rule : m_highlightRulescxx . . $ QPythonHighlighter#m_highlightRules.) |
| 109 | { |
| 110 | auto matchIterator = rulecxx . . $ QRegularExpressionMatchIterator#QRegularExpressionMatchIterator(42df41e057175116)..patterncxx . . $ QHighlightRule#pattern..globalMatchcxx . . $ QRegularExpression#globalMatch(72f8b242d28bebc1).(text); |
| 111 | |
| 112 | while (matchIterator.hasNextcxx . . $ QRegularExpressionMatchIterator#hasNext(50ce9a9e25b4a850).()) |
| 113 | { |
| 114 | auto match = matchIteratorcxx . . $ QRegularExpressionMatch#QRegularExpressionMatch(4c7bd13906b2250d)..nextcxx . . $ QRegularExpressionMatchIterator#next(5870644aafa115db).(); |
| 115 | |
| 116 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 117 | match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(), |
| 118 | match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(), |
| 119 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).(rulecxx . . $ QString#QString(3520e46b33348bf6)..formatNamecxx . . $ QHighlightRule#formatName.) |
| 120 | ); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | setCurrentBlockStatecxx . . $ QSyntaxHighlighter#setCurrentBlockState(d4f767463ce0a6b3).(0); |
| 125 | int startIndex = 0; |
| 126 | int highlightRuleId = previousBlockStatecxx . . $ QSyntaxHighlighter#previousBlockState(455f465bc33b4cdf).(); |
| 127 | if (highlightRuleId < 1 || highlightRuleId > m_highlightBlockRulescxx . . $ QPythonHighlighter#m_highlightBlockRules..sizecxx . . $ QVector#size(455f465bc33b4cdf).()) { |
| 128 | for(int i = 0; i < m_highlightBlockRulescxx . . $ QPythonHighlighter#m_highlightBlockRules..sizecxx . . $ QVector#size(455f465bc33b4cdf).(); ++i) { |
| 129 | startIndex = text.indexOfcxx . . $ QString#indexOf(44433515e1b9e5ad).(m_highlightBlockRulescxx . . $ QPythonHighlighter#m_highlightBlockRules..atcxx . . $ QVector#at(e2681f9bb6b2f357).(i).startPatterncxx . . $ QHighlightBlockRule#startPattern.); |
| 130 | |
| 131 | if (startIndex >= 0) { |
| 132 | highlightRuleId = i + 1; |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | while (startIndex >= 0) |
| 139 | { |
| 140 | const auto &blockRules = m_highlightBlockRulescxx . . $ QPythonHighlighter#m_highlightBlockRules..atcxx . . $ QVector#at(e2681f9bb6b2f357).(highlightRuleId - 1); |
| 141 | auto match = blockRulescxx . . $ QRegularExpressionMatch#QRegularExpressionMatch(4c7bd13906b2250d)..endPatterncxx . . $ QHighlightBlockRule#endPattern..matchcxx . . $ QRegularExpression#match(76cd69b0d626af6c).(text, startIndex+1); // Should be + length of start pattern |
| 142 | |
| 143 | int endIndex = match.capturedStartcxx . . $ QRegularExpressionMatch#capturedStart(7ccb52b1bfe01045).(); |
| 144 | int matchLength = 0; |
| 145 | |
| 146 | if (endIndex == -1) |
| 147 | { |
| 148 | setCurrentBlockStatecxx . . $ QSyntaxHighlighter#setCurrentBlockState(d4f767463ce0a6b3).(highlightRuleId); |
| 149 | matchLength = text.lengthcxx . . $ QString#length(455f465bc33b4cdf).() - startIndex; |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | matchLength = endIndex - startIndex + match.capturedLengthcxx . . $ QRegularExpressionMatch#capturedLength(7ccb52b1bfe01045).(); |
| 154 | } |
| 155 | |
| 156 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).( |
| 157 | startIndex, |
| 158 | matchLength, |
| 159 | syntaxStylecxx . . $ QStyleSyntaxHighlighter#syntaxStyle(8b4bb56ba20b4a4a).()->getFormatcxx . . $ QSyntaxStyle#getFormat(5b7fd501ba56a402).(blockRulescxx . . $ QString#QString(3520e46b33348bf6)..formatNamecxx . . $ QHighlightBlockRule#formatName.) |
| 160 | ); |
| 161 | startIndex = text.indexOfcxx . . $ QString#indexOf(44433515e1b9e5ad).(blockRules.startPatterncxx . . $ QHighlightBlockRule#startPattern., startIndex + matchLength); |
| 162 | } |
| 163 | } |