void HBQSyntaxHighlighter::hbSetRule( QString name, QString pattern, const QTextCharFormat & format ) { if( pattern != "" ) HighlightingRules.insert( name, HighlightingRule( QRegExp( pattern ), format ) ); else HighlightingRules.remove( name ); }
PlanHighlighter::PlanHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent) { //Operator /* operatorFormat.setForeground(QColor("green")); operatorFormat.setFontItalic(true); QStringList operatorPatterns; operatorPatterns << "\\b+\\b" ; //<< "\\b\\-\\b" << "\\b\\*\\b" << "\\b\\!\\b"<< "\\b\\%\\b"<< "\\b\\&\\b" << "\\b\\/\\b"; foreach (const QString &pattern, operatorPatterns) { rule.pattern = QRegExp(pattern); rule.format = operatorFormat; highlightingRules.append(rule); } */ //Paren parenFormat.setForeground(QColor("#ffffff")); QStringList parenPatterns; parenPatterns << "\\b\\{\\b" << "\\b\\}\\b" << "\\b\\[\\b" << "\\b\\]\\b" << "\\b\\(\\b" << "\\b\\)\\b"; foreach (const QString &pattern, parenPatterns) { highlightingRules.append(HighlightingRule (QRegExp(pattern), parenFormat)); }
TAO_BEGIN XLHighlighter::XLHighlighter(QTextDocument *parent) // ---------------------------------------------------------------------------- // Define the patterns and formats for the XL syntax // ---------------------------------------------------------------------------- : QSyntaxHighlighter(parent) { QColor selectedColor("#FFFF30"); QColor longTextColor("#005500"); // Build the highlighting rules highlightingRules // Infix, postfix, prefix and names << HighlightingRule(Qt::darkCyan, "", "") << HighlightingRule(Qt::darkYellow, "", "") << HighlightingRule(Qt::darkMagenta, "", "") << HighlightingRule(Qt::darkGray, "", "") // Digits << HighlightingRule(Qt::darkBlue, "\\d*\\.?\\d+") // Text << HighlightingRule(Qt::darkGreen, "\"[^\"]*\"") << HighlightingRule(Qt::darkGreen, "'[^']*'") // Multiline text << HighlightingRule(Qt::darkGreen, "<<", ">>") // Single line comment << HighlightingRule(Qt::darkRed, "//[^\n]*") // Multi-line comment << HighlightingRule(Qt::darkRed, "/\\*", "\\*/"); selectedFormat.setBackground(selectedColor); }
void HBQSyntaxHighlighter::hbSetFormat( QString name, const QTextCharFormat & format ) { if( ( QString ) "TerminatedStrings" == name ) { quotationFormat = format; } else { if( HighlightingRules.contains( name ) ) { HighlightingRule rule = HighlightingRules.value( name ); QRegExp reg = rule.pattern; HighlightingRules.insert( name, HighlightingRule( reg, format ) ); } else { HighlightingRules.remove( name ); } } }
//------------------------------------------------------------------------------ // Name: create_rules // Desc: //------------------------------------------------------------------------------ void SyntaxHighlighter::create_rules() { // TODO: make these rules be implemented in a portable way // right now things are very much hard coded // TODO: support segments QSettings settings; settings.beginGroup("Theme"); // comma rules_.append(HighlightingRule( "(,)", QColor(settings.value("theme.brackets.foreground", "blue").value<QString>()), QColor(settings.value("theme.brackets.background", "transparent").value<QString>()), settings.value("theme.brackets.weight", QFont::Normal).value<int>(), settings.value("theme.brackets.italic", false).value<bool>(), settings.value("theme.brackets.underline", false).value<bool>() )); // expression brackets rules_.append(HighlightingRule( "([\\[\\]])", QColor(settings.value("theme.brackets.foreground", "blue").value<QString>()), QColor(settings.value("theme.brackets.background", "transparent").value<QString>()), settings.value("theme.brackets.weight", QFont::Normal).value<int>(), settings.value("theme.brackets.italic", false).value<bool>(), settings.value("theme.brackets.underline", false).value<bool>() )); // math operators rules_.append(HighlightingRule( "\\b([\\+\\-\\*])\\b", QColor(settings.value("theme.operator.foreground", "blue").value<QString>()), QColor(settings.value("theme.operator.background", "transparent").value<QString>()), settings.value("theme.operator.weight", QFont::Normal).value<int>(), settings.value("theme.operator.italic", false).value<bool>(), settings.value("theme.operator.underline", false).value<bool>() )); // registers // TODO: support ST(N) rules_.append(HighlightingRule( "\\b(((e|r)?(ax|bx|cx|dx|bp|sp|si|di|ip))|([abcd](l|h))|(sp|bp|si|di)l|([cdefgs]s)|(x?mm[0-7])|r(8|9|(1[0-5]))[dwb]?)\\b", QColor(settings.value("theme.register.foreground", "red").value<QString>()), QColor(settings.value("theme.register.background", "transparent").value<QString>()), settings.value("theme.register.weight", QFont::Bold).value<int>(), settings.value("theme.register.italic", false).value<bool>(), settings.value("theme.register.underline", false).value<bool>() )); // constants rules_.append(HighlightingRule( "\\b((0[0-7]*)|(0(x|X)[0-9a-fA-F]+)|([1-9][0-9]*))\\b", QColor(settings.value("theme.constant.foreground", "black").value<QString>()), QColor(settings.value("theme.constant.background", "transparent").value<QString>()), settings.value("theme.constant.weight", QFont::Normal).value<int>(), settings.value("theme.constant.italic", false).value<bool>(), settings.value("theme.constant.underline", false).value<bool>() )); // pointer modifiers rules_.append(HighlightingRule( "\\b(t?byte|(xmm|[qdf]?)word) ptr\\b", QColor(settings.value("theme.ptr.foreground", "darkGreen").value<QString>()), QColor(settings.value("theme.ptr.background", "transparent").value<QString>()), settings.value("theme.ptr.weight", QFont::Normal).value<int>(), settings.value("theme.ptr.italic", false).value<bool>(), settings.value("theme.ptr.underline", false).value<bool>() )); // prefix rules_.append(HighlightingRule( "\\b(lock|rep(ne)?)\\b", QColor(settings.value("theme.prefix.foreground", "black").value<QString>()), QColor(settings.value("theme.prefix.background", "transparent").value<QString>()), settings.value("theme.prefix.weight", QFont::Bold).value<int>(), settings.value("theme.prefix.italic", false).value<bool>(), settings.value("theme.prefix.underline", false).value<bool>() )); // flow control rules_.append(HighlightingRule( "\\b(jmp|jn?[blopsz]|jn?[bl]e|jcez|loopn?[ez])\\b", QColor(settings.value("theme.flow_ctrl.foreground", "blue").value<QString>()), QColor(settings.value("theme.flow_ctrl.background", "yellow").value<QString>()), settings.value("theme.flow_ctrl.weight", QFont::Normal).value<int>(), settings.value("theme.flow_ctrl.italic", false).value<bool>(), settings.value("theme.flow_ctrl.underline", false).value<bool>() )); // function call rules_.append(HighlightingRule( "\\b(call|retn?)\\b", QColor(settings.value("theme.function.foreground", "blue").value<QString>()), QColor(settings.value("theme.function.background", "yellow").value<QString>()), settings.value("theme.function.weight", QFont::Normal).value<int>(), settings.value("theme.function.italic", false).value<bool>(), settings.value("theme.function.underline", false).value<bool>() )); // stack operations rules_.append(HighlightingRule( "\\b(pushf?|popf?|enter|leave)\\b", QColor(settings.value("theme.stack.foreground", "blue").value<QString>()), QColor(settings.value("theme.stack.background", "transparent").value<QString>()), settings.value("theme.stack.weight", QFont::Normal).value<int>(), settings.value("theme.stack.italic", false).value<bool>(), settings.value("theme.stack.underline", false).value<bool>() )); // comparison rules_.append(HighlightingRule( "\\b(cmp|test)\\b", QColor(settings.value("theme.comparison.foreground", "blue").value<QString>()), QColor(settings.value("theme.comparison.background", "transparent").value<QString>()), settings.value("theme.comparison.weight", QFont::Normal).value<int>(), settings.value("theme.comparison.italic", false).value<bool>(), settings.value("theme.comparison.underline", false).value<bool>() )); // data transfer rules_.append(HighlightingRule( "\\b(c?movs[bw]|lea|xchg|mov([zs]x?)?)\\b", QColor(settings.value("theme.data_xfer.foreground", "blue").value<QString>()), QColor(settings.value("theme.data_xfer.background", "transparent").value<QString>()), settings.value("theme.data_xfer.weight", QFont::Normal).value<int>(), settings.value("theme.data_xfer.italic", false).value<bool>(), settings.value("theme.data_xfer.underline", false).value<bool>() )); // arithmetic rules_.append(HighlightingRule( "\\b(add|sub|i?mul|i?div|neg|adc|sbb|inc|dec)\\b", QColor(settings.value("theme.arithmetic.foreground", "blue").value<QString>()), QColor(settings.value("theme.arithmetic.background", "transparent").value<QString>()), settings.value("theme.arithmetic.weight", QFont::Normal).value<int>(), settings.value("theme.arithmetic.italic", false).value<bool>(), settings.value("theme.arithmetic.underline", false).value<bool>() )); // logic rules_.append(HighlightingRule( "\\b(and|x?or|not)\\b", QColor(settings.value("theme.logic.foreground", "blue").value<QString>()), QColor(settings.value("theme.logic.background", "transparent").value<QString>()), settings.value("theme.logic.weight", QFont::Normal).value<int>(), settings.value("theme.logic.italic", false).value<bool>(), settings.value("theme.logic.underline", false).value<bool>() )); // shift rules_.append(HighlightingRule( "\\b(sh|sa|sc|ro)[rl]\\b", QColor(settings.value("theme.shift.foreground", "blue").value<QString>()), QColor(settings.value("theme.shift.background", "transparent").value<QString>()), settings.value("theme.shift.weight", QFont::Normal).value<int>(), settings.value("theme.shift.italic", false).value<bool>(), settings.value("theme.shift.underline", false).value<bool>() )); // system rules_.append(HighlightingRule( "\\b(sti|cli|hlt|in|out|sysenter|sysexit|syscall|sysret|int)\\b", QColor(settings.value("theme.system.foreground", "blue").value<QString>()), QColor(settings.value("theme.system.background", "transparent").value<QString>()), settings.value("theme.system.weight", QFont::Bold).value<int>(), settings.value("theme.system.italic", false).value<bool>(), settings.value("theme.system.underline", false).value<bool>() )); }
void MIPS32SyntaxHighlighter::rebuildHighlightingRules(){ highlightingRules.clear(); //use correct order for nested matches highlightingRules.push_back(HighlightingRule(literalDecimalRegex, literalDecimalFormat)); highlightingRules.push_back(HighlightingRule(literalOctalRegex, literalOctalFormat)); highlightingRules.push_back(HighlightingRule(literalBinRegex, literalBinFormat)); highlightingRules.push_back(HighlightingRule(literalHexRegex, literalHexFormat)); highlightingRules.push_back(HighlightingRule(GPRegisterMnemonicRegex, GPRegisterMnemonicFormat)); highlightingRules.push_back(HighlightingRule(GPRegisterNumericRegex, GPRegisterNumericFormat)); highlightingRules.push_back(HighlightingRule(FPRegisterRegex, FPRegisterFormat)); highlightingRules.push_back(HighlightingRule(directiveRegex, directiveFormat)); highlightingRules.push_back(HighlightingRule(labelRegex, labelFormat)); highlightingRules.push_back(HighlightingRule(literalStringRegex, literalStringFormat)); highlightingRules.push_back(HighlightingRule(commentSingleRegex, commentSingleFormat)); highlightingRules.push_back(HighlightingRule(commentDoubleRegex, commentDoubleFormat)); }
void HBQSyntaxHighlighter::hbSetRuleWithRegExp( QString name, const QRegExp & reg, const QTextCharFormat & format ) { HighlightingRules.insert( name, HighlightingRule( reg, format ) ); }
foreach (QString currBuiltin, builtins) { rules.append(HighlightingRule(QString("\\b%1\\b").arg(currBuiltin), 0, basicStyles.value("builtins"))); }
foreach (QString currExcept, exceptions) { rules.append(HighlightingRule(QString("\\b%1\\b").arg(currExcept), 0, basicStyles.value("except"))); }
foreach (QString currBrace, braces) { rules.append(HighlightingRule(QString("%1").arg(currBrace), 0, basicStyles.value("brace"))); }
foreach (QString currOperator, operators) { rules.append(HighlightingRule(QString("%1").arg(currOperator), 0, basicStyles.value("operator"))); }
foreach (QString currKeyword, keywords) { rules.append(HighlightingRule(QString("\\b%1\\b").arg(currKeyword), 0, basicStyles.value("keyword"))); }
foreach (QString currOperator, operators) { rules.append(HighlightingRule(QString("%1").arg(currOperator), 0, basicStyles.value("operator"))); } foreach (QString currBrace, braces) { rules.append(HighlightingRule(QString("%1").arg(currBrace), 0, basicStyles.value("brace"))); } foreach (QString currExcept, exceptions) { rules.append(HighlightingRule(QString("\\b%1\\b").arg(currExcept), 0, basicStyles.value("except"))); } rules.append( HighlightingRule("\\b__[\\w_]+__\\b", 0, basicStyles.value("hackish"))); rules.append( HighlightingRule("\\b_[\\w_]+\\b", 0, basicStyles.value("private"))); foreach (QString currBuiltin, builtins) { rules.append(HighlightingRule(QString("\\b%1\\b").arg(currBuiltin), 0, basicStyles.value("builtins"))); } rules.append(HighlightingRule("\\b_\\b", 0, basicStyles.value("special"))); rules.append(HighlightingRule("\\bself\\b", 0, basicStyles.value("special"))); rules.append(HighlightingRule( "(b|B|br|Br|bR|BR|rb|rB|Rb|RB)\"[^\"\\\\]*(\\\\.[^\"\\\\]*)*\"", 0, basicStyles.value("bytes"))); rules.append(HighlightingRule(
foreach (const QString &pattern, keywordPatterns) { highlightingRules.append(HighlightingRule (QRegExp(pattern), keywordFormat)); }
//Keyword keywordFormat.setForeground(QColor("#e9d000")); keywordFormat.setFontWeight(QFont::Bold); QStringList keywordPatterns; keywordPatterns << "\\bplan\\b" << "\\bpuppet\\b" << "\\bmember\\b" << "\\blimb\\b"; foreach (const QString &pattern, keywordPatterns) { highlightingRules.append(HighlightingRule (QRegExp(pattern), keywordFormat)); } //Hub hubFormat.setForeground(QColor("#45de47")); hubFormat.setFontWeight(QFont::Bold); highlightingRules.append(HighlightingRule (QRegExp("\\bhub\\b"), hubFormat)); //Remote remoteFormat.setForeground(QColor("#2faad0")); remoteFormat.setFontWeight(QFont::Bold); highlightingRules.append(HighlightingRule (QRegExp("\\bremote\\b"), remoteFormat)); //Agent agentFormat.setForeground(QColor("#da3333")); agentFormat.setFontWeight(QFont::Bold); highlightingRules.append(HighlightingRule (QRegExp("\\bagent\\b"), agentFormat)); operatorFormat.setFontWeight(QFont::Bold); operatorFormat.setForeground(QColor("#d0e900")); highlightingRules.append(HighlightingRule (QRegExp("\\b[\\\\+" + QRegExp::escape("e+-*/!=<>")+ "]+\\b"), operatorFormat));
} void PythonSyntaxHighlighter::initializeRules() { foreach (QString currKeyword, keywords) { rules.append(HighlightingRule(QString("\\b%1\\b").arg(currKeyword), 0, basicStyles.value("keyword"))); } foreach (QString currOperator, operators) { rules.append(HighlightingRule(QString("%1").arg(currOperator), 0, basicStyles.value("operator"))); } foreach (QString currBrace, braces) { rules.append(HighlightingRule(QString("%1").arg(currBrace), 0, basicStyles.value("brace"))); } // 'self' rules.append(HighlightingRule("\\bself\\b", 0, basicStyles.value("self"))); // Double-quoted string, possibly containing escape sequences // FF: originally in python : r'"[^"\\]*(\\.[^"\\]*)*"' rules.append(HighlightingRule("\"[^\"\\\\]*(\\\\.[^\"\\\\]*)*\"", 0, basicStyles.value("string"))); // Single-quoted string, possibly containing escape sequences // FF: originally in python : r"'[^'\\]*(\\.[^'\\]*)*'" rules.append(HighlightingRule("'[^'\\\\]*(\\\\.[^'\\\\]*)*'", 0, basicStyles.value("string"))); // 'def' followed by an identifier // FF: originally: r'\bdef\b\s*(\w+)' rules.append(HighlightingRule("\\bdef\\b\\s*(\\w+)", 1, basicStyles.value("defclass"))); // 'class' followed by an identifier // FF: originally: r'\bclass\b\s*(\w+)' rules.append(HighlightingRule("\\bclass\\b\\s*(\\w+)", 1, basicStyles.value("defclass")));