| 1 | // File: cpphighlighter.cppcxx . . $ `<file>/cpphighlighter.cpp`/ |
| 2 | /* |
| 3 | Pep8-1 is a virtual machine for writing machine language and assembly |
| 4 | language programs. |
| 5 | |
| 6 | Copyright (C) 2009 J. Stanley Warford, Pepperdine University |
| 7 | |
| 8 | This program is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | #include "cpphighlighter.h"cxx . . $ `<file>/cpphighlighter.h`/ |
| 22 | |
| 23 | CppHighlightercxx . . $ CppHighlighter#::CppHighlightercxx . . $ CppHighlighter#CppHighlighter(68d7deb16251beb9).(QTextDocumentcxx . . $ QTextDocument# *parent) |
| 24 | : QSyntaxHighlightercxx . . $ QSyntaxHighlighter#QSyntaxHighlighter(68d7deb16251beb9).(parent) |
| 25 | { |
| 26 | HighlightingRulecxx . . $ CppHighlighter#HighlightingRule# rule; |
| 27 | |
| 28 | |
| 29 | // functionFormat.setFontItalic(true); |
| 30 | functionFormatcxx . . $ CppHighlighter#functionFormat..setFontWeightcxx . . $ QTextCharFormat#setFontWeight(d4f767463ce0a6b3).(QFontcxx . . $ QFont#::Boldcxx . . $ QFont#Bold.); |
| 31 | functionFormatcxx . . $ CppHighlighter#functionFormat..setForegroundcxx . . $ QTextFormat#setForeground(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::darkMagentacxx . . $ Qt/darkMagenta.); |
| 32 | rule.patterncxx . . $ CppHighlighter#HighlightingRule#pattern. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("\\b[A-Za-z0-9_]+(?=[\\s]*\\()"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 33 | rule.formatcxx . . $ CppHighlighter#HighlightingRule#format. =cxx . . $ QTextCharFormat#`operator=`(74fb0fd9fc0c28a7). functionFormatcxx . . $ CppHighlighter#functionFormat.; |
| 34 | highlightingRulescxx . . $ CppHighlighter#highlightingRules..appendcxx . . $ QVector#append(77d9f17553126ecb).(rule); |
| 35 | |
| 36 | declarationFormatcxx . . $ CppHighlighter#declarationFormat..setFontItaliccxx . . $ QTextCharFormat#setFontItalic(b45ddcbc8423892c).(true); |
| 37 | declarationFormatcxx . . $ CppHighlighter#declarationFormat..setForegroundcxx . . $ QTextFormat#setForeground(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::darkBluecxx . . $ Qt/darkBlue.); |
| 38 | QStringListcxx . . $ QStringList# declarationPatternscxx . . $ QStringList#QStringList(ced63f7c635d850d).; |
| 39 | declarationPatterns <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bbool\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bchar\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bconst\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bcase\\b"cxx . . $ QString#QString(85c52e162fed56f9). |
| 40 | <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\benum\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bint\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bnamespace\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bstruct\\b"cxx . . $ QString#QString(85c52e162fed56f9). |
| 41 | <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\busing\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\#include\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bvoid\\b"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 42 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (const QString &pattern, declarationPatterns) { |
| 43 | rule.patterncxx . . $ CppHighlighter#HighlightingRule#pattern. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).(pattern); |
| 44 | rule.formatcxx . . $ CppHighlighter#HighlightingRule#format. =cxx . . $ QTextCharFormat#`operator=`(74fb0fd9fc0c28a7). declarationFormatcxx . . $ CppHighlighter#declarationFormat.; |
| 45 | highlightingRulescxx . . $ CppHighlighter#highlightingRules..appendcxx . . $ QVector#append(77d9f17553126ecb).(rule); |
| 46 | } |
| 47 | |
| 48 | keywordFormatcxx . . $ CppHighlighter#keywordFormat..setForegroundcxx . . $ QTextFormat#setForeground(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::darkBluecxx . . $ Qt/darkBlue.); |
| 49 | keywordFormatcxx . . $ CppHighlighter#keywordFormat..setFontWeightcxx . . $ QTextCharFormat#setFontWeight(d4f767463ce0a6b3).(QFontcxx . . $ QFont#::Boldcxx . . $ QFont#Bold.); |
| 50 | QStringListcxx . . $ QStringList# keywordPatternscxx . . $ QStringList#QStringList(ced63f7c635d850d).; |
| 51 | keywordPatterns <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bwhile\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bfor\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bswitch\\b"cxx . . $ QString#QString(85c52e162fed56f9). |
| 52 | <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bif\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bdo\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\bnew\\b"cxx . . $ QString#QString(85c52e162fed56f9). |
| 53 | <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\breturn\\b"cxx . . $ QString#QString(85c52e162fed56f9). <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "\\belse\\b"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 54 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (const QString &pattern, keywordPatterns) { |
| 55 | rule.patterncxx . . $ CppHighlighter#HighlightingRule#pattern. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).(pattern); |
| 56 | rule.formatcxx . . $ CppHighlighter#HighlightingRule#format. =cxx . . $ QTextCharFormat#`operator=`(74fb0fd9fc0c28a7). keywordFormatcxx . . $ CppHighlighter#keywordFormat.; |
| 57 | highlightingRulescxx . . $ CppHighlighter#highlightingRules..appendcxx . . $ QVector#append(77d9f17553126ecb).(rule); |
| 58 | } |
| 59 | |
| 60 | classFormatcxx . . $ CppHighlighter#classFormat..setFontWeightcxx . . $ QTextCharFormat#setFontWeight(d4f767463ce0a6b3).(QFontcxx . . $ QFont#::Boldcxx . . $ QFont#Bold.); |
| 61 | classFormatcxx . . $ CppHighlighter#classFormat..setForegroundcxx . . $ QTextFormat#setForeground(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::darkMagentacxx . . $ Qt/darkMagenta.); |
| 62 | rule.patterncxx . . $ CppHighlighter#HighlightingRule#pattern. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("\\bQ[A-Za-z]+\\b"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 63 | rule.formatcxx . . $ CppHighlighter#HighlightingRule#format. =cxx . . $ QTextCharFormat#`operator=`(74fb0fd9fc0c28a7). classFormatcxx . . $ CppHighlighter#classFormat.; |
| 64 | highlightingRulescxx . . $ CppHighlighter#highlightingRules..appendcxx . . $ QVector#append(77d9f17553126ecb).(rule); |
| 65 | |
| 66 | singleLineCommentFormatcxx . . $ CppHighlighter#singleLineCommentFormat..setForegroundcxx . . $ QTextFormat#setForeground(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::darkGreencxx . . $ Qt/darkGreen.); |
| 67 | rule.patterncxx . . $ CppHighlighter#HighlightingRule#pattern. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("//[^\n]*"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 68 | rule.formatcxx . . $ CppHighlighter#HighlightingRule#format. =cxx . . $ QTextCharFormat#`operator=`(74fb0fd9fc0c28a7). singleLineCommentFormatcxx . . $ CppHighlighter#singleLineCommentFormat.; |
| 69 | highlightingRulescxx . . $ CppHighlighter#highlightingRules..appendcxx . . $ QVector#append(77d9f17553126ecb).(rule); |
| 70 | |
| 71 | multiLineCommentFormatcxx . . $ CppHighlighter#multiLineCommentFormat..setForegroundcxx . . $ QTextFormat#setForeground(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::darkGreencxx . . $ Qt/darkGreen.); |
| 72 | |
| 73 | singleQuotationFormatcxx . . $ CppHighlighter#singleQuotationFormat..setForegroundcxx . . $ QTextFormat#setForeground(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::redcxx . . $ Qt/red.); |
| 74 | rule.patterncxx . . $ CppHighlighter#HighlightingRule#pattern. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("((\')(?![\'])(([^\'|\\\\]){1}|((\\\\)([\'|b|f|n|r|t|v|\"|\\\\]))|((\\\\)(([x|X])([0-9|A-F|a-f]{2}))))(\'))"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 75 | rule.formatcxx . . $ CppHighlighter#HighlightingRule#format. =cxx . . $ QTextCharFormat#`operator=`(74fb0fd9fc0c28a7). singleQuotationFormatcxx . . $ CppHighlighter#singleQuotationFormat.; |
| 76 | highlightingRulescxx . . $ CppHighlighter#highlightingRules..appendcxx . . $ QVector#append(77d9f17553126ecb).(rule); |
| 77 | |
| 78 | doubleQuotationFormatcxx . . $ CppHighlighter#doubleQuotationFormat..setForegroundcxx . . $ QTextFormat#setForeground(ffc9f5d0bda78261).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::redcxx . . $ Qt/red.); |
| 79 | rule.patterncxx . . $ CppHighlighter#HighlightingRule#pattern. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("((\")((([^\"|\\\\])|((\\\\)([\'|b|f|n|r|t|v|\"|\\\\]))|((\\\\)(([x|X])([0-9|A-F|a-f]{2}))))*)(\"))"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 80 | rule.formatcxx . . $ CppHighlighter#HighlightingRule#format. =cxx . . $ QTextCharFormat#`operator=`(74fb0fd9fc0c28a7). doubleQuotationFormatcxx . . $ CppHighlighter#doubleQuotationFormat.; |
| 81 | highlightingRulescxx . . $ CppHighlighter#highlightingRules..appendcxx . . $ QVector#append(77d9f17553126ecb).(rule); |
| 82 | |
| 83 | commentStartExpressioncxx . . $ CppHighlighter#commentStartExpression. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("/\\*"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 84 | commentEndExpressioncxx . . $ CppHighlighter#commentEndExpression. =cxx . . $ QRegExp#`operator=`(ca041f4b0a7c2092). QRegExpcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("\\*/"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 85 | } |
| 86 | |
| 87 | void CppHighlightercxx . . $ CppHighlighter#::highlightBlockcxx . . $ CppHighlighter#highlightBlock(3520e46b33348bf6).(const QStringcxx . . $ QString# &text) |
| 88 | { |
| 89 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (const HighlightingRule &rule, highlightingRules) { |
| 90 | QRegExpcxx . . $ QRegExp# expressioncxx . . $ QRegExp#QRegExp(ff80efdedf7b2ca0).(rule.patterncxx . . $ CppHighlighter#HighlightingRule#pattern.); |
| 91 | int index = expression.indexIncxx . . $ QRegExp#indexIn(46f502bdfc4aeb33).(text); |
| 92 | while (index >= 0) { |
| 93 | int length = expression.matchedLengthcxx . . $ QRegExp#matchedLength(455f465bc33b4cdf).(); |
| 94 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).(index, length, rule.formatcxx . . $ CppHighlighter#HighlightingRule#format.); |
| 95 | index = expression.indexIncxx . . $ QRegExp#indexIn(46f502bdfc4aeb33).(text, index + length); |
| 96 | } |
| 97 | } |
| 98 | setCurrentBlockStatecxx . . $ QSyntaxHighlighter#setCurrentBlockState(d4f767463ce0a6b3).(0); |
| 99 | |
| 100 | int startIndex = 0; |
| 101 | if (previousBlockStatecxx . . $ QSyntaxHighlighter#previousBlockState(455f465bc33b4cdf).() != 1) |
| 102 | startIndex = commentStartExpressioncxx . . $ CppHighlighter#commentStartExpression..indexIncxx . . $ QRegExp#indexIn(46f502bdfc4aeb33).(text); |
| 103 | |
| 104 | while (startIndex >= 0) { |
| 105 | int endIndex = commentEndExpressioncxx . . $ CppHighlighter#commentEndExpression..indexIncxx . . $ QRegExp#indexIn(46f502bdfc4aeb33).(text, startIndex); |
| 106 | int commentLength; |
| 107 | if (endIndex == -1) { |
| 108 | setCurrentBlockStatecxx . . $ QSyntaxHighlighter#setCurrentBlockState(d4f767463ce0a6b3).(1); |
| 109 | commentLength = text.lengthcxx . . $ QString#length(455f465bc33b4cdf).() - startIndex; |
| 110 | } else { |
| 111 | commentLength = endIndex - startIndex |
| 112 | + commentEndExpressioncxx . . $ CppHighlighter#commentEndExpression..matchedLengthcxx . . $ QRegExp#matchedLength(455f465bc33b4cdf).(); |
| 113 | } |
| 114 | setFormatcxx . . $ QSyntaxHighlighter#setFormat(c9121f7a6060c957).(startIndex, commentLength, multiLineCommentFormatcxx . . $ CppHighlighter#multiLineCommentFormat.); |
| 115 | startIndex = commentStartExpressioncxx . . $ CppHighlighter#commentStartExpression..indexIncxx . . $ QRegExp#indexIn(46f502bdfc4aeb33).(text, startIndex + commentLength); |
| 116 | } |
| 117 | } |