void HEMSyntaxHighlighter::highlightBlock(const QString &text) { for (const HighlightingRule &rule : highlightingRules) { QRegExp expression(rule.pattern); int index = expression.indexIn(text); while (index >= 0) { int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(text, index + length); } } setCurrentBlockState(STATE_NORMAL); int startIndex = 0; QRegExp include("\\binclude\\b"), newline("\\r?\\n"); int ilength = QString("include").length(); // 7 if (previousBlockState() != STATE_INCLUDE) startIndex = include.indexIn(text) + ilength; while (startIndex >= ilength) { int endIndex = newline.indexIn(text); int includeLength; if (endIndex == -1) { setCurrentBlockState(STATE_INCLUDE); includeLength = text.length() - startIndex; } else { includeLength = endIndex - startIndex + newline.matchedLength(); } setFormat(startIndex, includeLength, includeFileFormat); startIndex = include.indexIn(text, startIndex + includeLength); } }
void CodeHighlighter::highlightCommentBlocks(const QString &text) { const QList<LexemeAppearance *> &lexemes = m_theme->blockLexemes(); for (const LexemeAppearance *lexeme : lexemes) { const QRegExp &startPattern = lexeme->pattern(); const QRegExp &endPattern = lexeme->endPattern(); setCurrentBlockState(0); int startIndex = 0; if (previousBlockState() != 1) startIndex = startPattern.indexIn(text); while (startIndex >= 0) { int endIndex = endPattern.indexIn(text, startIndex); int commentLength; if (endIndex == -1) { setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex + endPattern.matchedLength(); } setFormat(startIndex, commentLength, *lexeme->format()); startIndex = startPattern.indexIn(text, startIndex + commentLength); } } }
// Overrides the function from QSyntaxHighlighter; // gets called by QTextEditor whenever // a block (line of text) needs to be repainted void XHTMLHighlighter::highlightBlock(const QString &text) { // By default, all block states are -1; // in our implementation regular text is state == 1 if (previousBlockState() == -1) { setCurrentBlockState(State_Text); } // Propagate previous state; needed for state tracking else { setCurrentBlockState(previousBlockState()); } if (text.isEmpty()) { return; } SettingsStore settings; m_enableSpellCheck = settings.spellCheck(); // Run spell check over the text. if (m_enableSpellCheck && m_checkSpelling) { CheckSpelling(text); } // The order of these operations is important // because some states format text over previous states! HighlightLine(text, State_Entity); HighlightLine(text, State_CSS); HighlightLine(text, State_HTML); HighlightLine(text, State_CSSComment); HighlightLine(text, State_HTMLComment); HighlightLine(text, State_DOCTYPE); }
bool Highlighter::matchMultiline(const QString& text, const ::HighlightingRule& rule) { QRegExp delimiter(rule.pattern); int start = 0; int add = 0; int end = 0; int length = 0; if (previousBlockState() != rule.index) { start = delimiter.indexIn(text); add = delimiter.matchedLength(); } while (start >= 0) { end = delimiter.indexIn(text, start + add); if (end >= add) { length = end - start + add + delimiter.matchedLength(); setCurrentBlockState(0); } else { setCurrentBlockState(rule.index); length = text.length() - start + add; } QTextCharFormat fmt; if (m_Formats.contains(rule.t)) fmt = m_Formats[rule.t]; setFormat(start, length, fmt); start = delimiter.indexIn(text, start + length); } return currentBlockState() == rule.index; }
/** handle nested comments and simple minded attributes */ void lqGvSynCol::highlightBlock(const QString &text) { QString begComm("/\\*"); QString number("\\d+(?:\\.\\d+)?"); QString symbol("\\w+"); QString quoted("\"[^\"]*\""); QString edges("--|->"); QRegExp tokens(QString("(%1)|(%2)|(%3)|(%4)|(%5)|#").arg(begComm, number, symbol, quoted, edges)); QRegExp endComm("\\*/"); // simple state machine if (currentBlock().blockNumber() > 0) setCurrentBlockState(previousBlockState()); else setCurrentBlockState(0); for (int i = 0, j, l; ; i = j + l) if (currentBlockState()) { // in multiline comment if ((j = endComm.indexIn(text, i)) == -1) { setFormat(i, text.length() - i, fmt[Comm]); break; } setFormat(i, j - i + (l = 2), fmt[Comm]); setCurrentBlockState(0); } else { if ((j = tokens.indexIn(text, i)) == -1) break; QStringList ml = tokens.capturedTexts(); Q_ASSERT(ml.length() == 5+1); if ((l = ml[1].length())) { // begin multiline comment setFormat(j, l, fmt[Comm]); setCurrentBlockState(1); } else if ((l = ml[2].length())) { // number setFormat(j, l, fmt[Number]); } else if ((l = ml[3].length())) { // symbol if (keyws.contains(ml[3])) setFormat(j, l, fmt[Keyw]); else if (attrs.contains(ml[3])) setFormat(j, l, fmt[Attr]); else setFormat(j, l, fmt[Unknown]); } else if ((l = ml[4].length())) { // quoted setFormat(j, l, fmt[Quoted]); } else if ((l = ml[5].length())) { // edge setFormat(j, l, fmt[Edge]); } else { // single line comment setFormat(j, text.length() - i, fmt[Comm]); break; } } // rather useless - anyway textChanged will fire after completion if (currentBlock().blockNumber() == document()->blockCount() - 1) emit completed(); }
/** handle nested comments and simple minded Prolog syntax */ void plMiniSyntax::highlightBlock(const QString &text) { // simple state machine int nb = currentBlock().blockNumber(); if (nb > 0) { setCurrentBlockState(previousBlockState()); if (nb % 10 == 0) do_events(); } else { startToEnd.start(); qDebug() << "starting at " << QTime::currentTime(); setCurrentBlockState(0); } for (int i = 0, j, l; ; i = j + l) if (currentBlockState()) { // in multiline comment if ((j = text.indexOf("*/", i)) == -1) { setFormat(i, text.length() - i, fmt[Comment]); break; } setFormat(i, j - i + (l = 2), fmt[Comment]); setCurrentBlockState(0); } else { if ((j = text.indexOf("/*", i)) >= 0) { // begin multiline comment setFormat(j, l = 2, fmt[Comment]); setCurrentBlockState(1); } else { if ((j = tokens.indexIn(text, i)) == -1) break; QStringList ml = tokens.capturedTexts(); Q_ASSERT(ml.length() == 5+1); if ((l = ml[1].length())) { // number setFormat(j, l, fmt[Number]); } else if ((l = ml[2].length())) { // symbol setFormat(j, l, fmt[Atom]); } else if ((l = ml[3].length())) { // var setFormat(j, l, fmt[Variable]); } else if ((l = ml[4].length())) { // quoted setFormat(j, l, fmt[String]); } else if ((l = ml[5].length())) { // operator setFormat(j, l, fmt[Operator]); } else { // single line comment setFormat(j, text.length() - i, fmt[Comment]); break; } } } if (currentBlock() == document()->lastBlock()) qDebug() << "done at " << QTime::currentTime() << "in" << startToEnd.elapsed(); }
foreach (HighlightingRule rule, m_highlightingRules) { if(!rule.block) { QRegExp expression(rule.expression); int index = text.indexOf(expression); while (index >= 0) { int length = expression.matchedLength(); /*IntervallWithFormat temp; temp.index = index; temp.length = length; temp.format = rule.format; keywords.append(temp);*/ //setFormat(index, length, rule.format); applyFormat(index, length, rule.format); index = text.indexOf(expression, index + length); } } else { // mathMode setCurrentBlockState(0); int startIndex = 0; if (previousBlockState() != 1) //startIndex = text.indexOf(mathModeStartExpression); startIndex = text.indexOf(rule.startExpression); while (startIndex >= 0) { //int endIndex = text.indexOf(mathModeEndExpression, startIndex+1); int endIndex = text.indexOf(rule.endExpression, startIndex+1); int mathModeLength; if (endIndex == -1) { setCurrentBlockState(1); mathModeLength = text.length() - startIndex; } else { /*mathModeLength = endIndex - startIndex + mathModeEndExpression.matchedLength();*/ mathModeLength = endIndex - startIndex + rule.endExpression.matchedLength(); } /*IntervallWithFormat temp; temp.index = startIndex; temp.length = mathModeLength; temp.format = m_mathModeFormat; mathModes.append(temp);*/ //setFormat(startIndex, mathModeLength, m_mathModeFormat); applyFormat(startIndex, mathModeLength, m_mathModeFormat); /*startIndex = text.indexOf(mathModeStartExpression, startIndex + mathModeLength);*/ startIndex = text.indexOf(rule.startExpression, startIndex + mathModeLength); } } }
void Highlighter::highlightBlock(const QString &text) { if (!m_syntaxer) return; if (text.isEmpty()) { setCurrentBlockState(previousBlockState()); return; } setCurrentBlockState(0); int startCommentIndex = -1; int startStringIndex = -1; const CommentInfo * currentCommentInfo = NULL; int pbs = previousBlockState(); if (pbs <= 0) { m_syntaxer->matchCommentStart(text, 0, startCommentIndex, currentCommentInfo); } else if (pbs >= COMMENTOFFSET) { currentCommentInfo = m_syntaxer->getCommentInfo(previousBlockState() - COMMENTOFFSET); startCommentIndex = 0; } else if (pbs == STRINGOFFSET) { startStringIndex = 0; } QString noComment = text; while (startCommentIndex >= 0) { int endIndex = currentCommentInfo->m_multiLine ? text.indexOf(currentCommentInfo->m_end, startCommentIndex, currentCommentInfo->m_caseSensitive) : text.length(); int commentLength; if (endIndex == -1) { setCurrentBlockState(currentCommentInfo->m_index + COMMENTOFFSET); commentLength = text.length() - startCommentIndex; } else { commentLength = endIndex - startCommentIndex + currentCommentInfo->m_end.length(); } noComment.replace(startCommentIndex, commentLength, QString(commentLength, ' ')); QTextCharFormat * cf = m_styleFormats.value("Comment", NULL); if (cf != NULL) { setFormat(startCommentIndex, commentLength, *cf); } m_syntaxer->matchCommentStart(text, startCommentIndex + commentLength, startCommentIndex, currentCommentInfo); } highlightStrings(startStringIndex, noComment); highlightTerms(noComment); }
void Highlighter::highlightBlock(const QString &text) { int initialState = previousBlockState(); if (initialState == -1) initialState = 0; setCurrentBlockState(highlightLine(text, initialState)); }
// Clears the requested state for the current text block void XHTMLHighlighter::ClearState(int state) { int current_state = currentBlockState(); // Remove the current state from the list current_state = current_state & ~state; setCurrentBlockState(current_state); }
void SmkMarkHighlighter::highlightBlock(const QString& text) { // highlight with regrxp for(int i=0; i<format_.size(); i++) { int index = regexp_[i].indexIn(text); while(index >= 0) { int length = regexp_[i].matchedLength(); this->setFormat(index, length, format_[i]); index = regexp_[i].indexIn(text, index + length); } } // code block and latex block highlight if(currentBlockState() == -1) setCurrentBlockState(0); QTextCharFormat codeFormat; codeFormat.setForeground(QColor(qSmkApp()->option("color.code"))); _aux_multiBlockMatch(text, "`", "`", codeFormat, 0x0001); // _aux_multiBlockMatch(text, "``", "``", codeFormat, 0x0002); // _aux_multiBlockMatch(text, "```", "```", codeFormat, 0x004); QTextCharFormat latexFormat; latexFormat.setForeground(QColor(qSmkApp()->option("color.latex"))); _aux_multiBlockMatch(text, "${", "}$", latexFormat, 0x1000); _aux_multiBlockMatch(text, "$$", "$$", latexFormat, 0x2000); }
void QtScriptHighlighter::onBlockEnd(int state, int firstNonSpace) { typedef TextEditor::TextBlockUserData TextEditorBlockData; setCurrentBlockState((m_braceDepth << 8) | state); // Set block data parentheses. Force creation of block data unless empty TextEditorBlockData *blockData = 0; if (QTextBlockUserData *userData = currentBlockUserData()) blockData = static_cast<TextEditorBlockData *>(userData); if (!blockData && !m_currentBlockParentheses.empty()) { blockData = new TextEditorBlockData; setCurrentBlockUserData(blockData); } if (blockData) { blockData->setParentheses(m_currentBlockParentheses); blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::NoClosingCollapse); blockData->setCollapseMode(TextEditor::TextBlockUserData::NoCollapse); } if (!m_currentBlockParentheses.isEmpty()) { QTC_ASSERT(blockData, return); int collapse = Parenthesis::collapseAtPos(m_currentBlockParentheses); if (collapse >= 0) { if (collapse == firstNonSpace) blockData->setCollapseMode(TextEditor::TextBlockUserData::CollapseThis); else blockData->setCollapseMode(TextEditor::TextBlockUserData::CollapseAfter); } if (Parenthesis::hasClosingCollapse(m_currentBlockParentheses)) blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::NoClosingCollapse); }
void Highlighter::highlightBlock(const QString &text) { QTextCharFormat fmt; fmt.setFont(QFont(m_Palette->mainFont, m_Palette->mainFontPointSize)); setFormat(0, text.length(), fmt); foreach(const ::HighlightingRule& rule, kHighlightingRules.rules) { QRegExp expression(rule.pattern); int index = expression.indexIn(text); while (index >= 0) { index = expression.pos(rule.index); int length = expression.cap(rule.index).length(); if (m_Formats.contains(rule.t)) { fmt = m_Formats[rule.t]; setFormat(index, length, fmt); } index = expression.indexIn(text, index + length); } } setCurrentBlockState(0); bool isMultiline = matchMultiline(text, kHighlightingRules.triSingle); if (!isMultiline) isMultiline = matchMultiline(text, kHighlightingRules.triDouble); }
void EMailQuoteHighlighter::highlightBlock( const QString &text ) { QString simplified = text; simplified = simplified.remove( QRegExp( QLatin1String( "\\s" ) ) ). replace( QLatin1Char( '|' ), QLatin1Char( '>' ) ); while ( simplified.startsWith( QLatin1String( ">>>>" ) ) ) { simplified = simplified.mid( 3 ); } if ( simplified.startsWith( QLatin1String( ">>>" ) ) ) { setFormat( 0, text.length(), d->col3 ); } else if ( simplified.startsWith( QLatin1String( ">>" ) ) ) { setFormat( 0, text.length(), d->col2 ); } else if ( simplified.startsWith( QLatin1String( ">" ) ) ) { setFormat( 0, text.length(), d->col1 ); } else if ( d->parent->isLineQuoted( text ) ) { setFormat( 0, text.length(), d->col1 ); // FIXME: custom quote prefix // can't handle multiple levels } else { if ( d->spellCheckingEnabled && checkerEnabledByDefault() ) { Highlighter::highlightBlock( text ); } } setCurrentBlockState( 0 ); }
// Sets the requested state for the current text block void XHTMLHighlighter::SetState(int state) { int current_state = currentBlockState(); // Add the current state to the list current_state = current_state | state; setCurrentBlockState(current_state); }
foreach (const MultilineHighlightingRule &rule, multilineHighlightingRules) { QRegExp startExpression(rule.patternStart); QRegExp endExpression(rule.patternEnd); int startIndex = 0; if (previousBlockState() != rule.statusCode) { startIndex = startExpression.indexIn(text); } while (startIndex >= 0) { int endIndex = endExpression.indexIn(text, startIndex); int matchLength; if (endIndex == -1) { setCurrentBlockState(rule.statusCode); matchLength = text.length() - startIndex; } else { matchLength = endIndex - startIndex + endExpression.matchedLength(); } setFormat(startIndex, matchLength, rule.format); startIndex = rule.patternStart.indexIn(text, startIndex + matchLength); } }
logical OSyntaxHighlighter :: FindElements (QString qsText, int32 &riStart ) { logical term = NO; int iEnd = 0 ,iStart = riStart ,iLength = 0; std::vector<SyntaxElement>::iterator it; BEGINSEQ if(qsText.isEmpty()) ERROR for ( it = elements.begin(); it != elements.end() && !term; ++it ){ iStart = riStart; while ( iStart >= 0 ) if(FindElement(qsText,iStart,(*it).rxStart)){ iLength = (*it).rxStart.cap(0).length(); iEnd = iStart+iLength; if((*it).isBlock) if(FindElement(qsText,iEnd,(*it).rxEnd)){ //highlight the block to the end of line iLength = (iEnd + (*it).rxStart.cap(0).length()) - iStart; }else{ // remember that the block doesnt end here iLength = qsText.length() - iStart; setCurrentBlockState(GetSyntaxElementIndex((*it))); } AddFormatRange((*it).syntaxclass,iStart,iLength); iStart+=iLength; } } RECOVER term = YES; ENDSEQ return term; }
bool BashHighlighter::matchMultiline(const QString& text, const QRegExp& delimiter, const int inState, const QTextCharFormat& style) { int start = -1; int add = -1; int end = -1; int length = 0; // If inside triple-single quotes, start at 0 if ( previousBlockState() == inState ) { start = 0; add = 0; } // Otherwise, look for the delimiter on this line else { start = delimiter.indexIn(text); // Move past this match add = delimiter.matchedLength(); } // As long as there's a delimiter match on this line... while ( start >= 0 ) { // Look for the ending delimiter end = delimiter.indexIn(text, start + add); // Ending delimiter on this line? if ( end >= add ) { length = end - start + add + delimiter.matchedLength(); setCurrentBlockState(0); } // No; multi-line string else { setCurrentBlockState(inState); length = text.length() - start + add; } // Apply formatting and look for next setFormat(start, length, style); start = delimiter.indexIn(text, start + length); } // Return True if still inside a multi-line string, False otherwise if ( currentBlockState() == inState ) return true; else return false; }
void QMLHighlighter::highlightBlock(const QString &text) { QTextCharFormat keywordFormat; keywordFormat.setForeground(QColor("#d7ffaf")); // Identifier QTextCharFormat typeFormat; typeFormat.setForeground(QColor("#afffff")); // Type QTextCharFormat commentFormat; commentFormat.setForeground(QColor("#8a8a8a")); // Comment QTextCharFormat numericConstantFormat; numericConstantFormat.setForeground(QColor("#ffffd7")); // Constant QTextCharFormat stringConstantFormat; stringConstantFormat.setForeground(QColor("#ffffd7")); QRegExp type("\\b[A-Z][A-Za-z]+\\b"); QRegExp numericConstant("[0-9]+\\.?[0-9]*"); QRegExp stringConstant("['\"].*['\"]");//Not multiline strings, but they're rare QRegExp lineComment("//[^\n]*"); QRegExp startComment("/\\*"); QRegExp endComment("\\*/"); applyBasicHighlight(text, type, typeFormat); applyBasicHighlight(text, numericConstant, numericConstantFormat); applyBasicHighlight(text, stringConstant, stringConstantFormat); applyBasicHighlight(text, lineComment, commentFormat); setCurrentBlockState(0); int startIndex = 0; if (previousBlockState() != 1) startIndex = text.indexOf(startComment); while (startIndex >= 0) { int endIndex = text.indexOf(endComment, startIndex); int commentLength; if (endIndex == -1) { setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex + endComment.matchedLength(); } setFormat(startIndex, commentLength, commentFormat); startIndex = text.indexOf(startComment, startIndex + commentLength); } }
void SyntaxHighlighter::highlightBlock(const QString& str) { int nState = previousBlockState(); int nStart = 0; for(int i = 0; i < str.length(); ++i) { if(nState == InsideCStyleComment) { if(str.mid(i, 2) == "*/") { nState = NormalState; setFormat(nStart, i - nStart + 2, Qt::darkGray); i++; } } else if(nState == InsideCString) { if (str.mid(i, 1) == "\"" || str.mid(i, 1) == "\'") { if (str.mid(i - 1, 2) != "\\\"" && str.mid(i - 1, 2) != "\\\'") { nState = NormalState; setFormat(nStart, i - nStart + 1, Qt::cyan); } } } else { if (str.mid(i, 2) == "//") { setFormat(i, str.length() - i, Qt::darkGray); break; } else if (str.mid(i, 1) == "#") { setFormat(i, str.length() - i, Qt::green); break; } else if (str.at(i).isNumber()) { setFormat(i, 1, Qt::cyan); } else if (str.mid(i, 2) == "/*") { nStart = i; nState = InsideCStyleComment; } else if (str.mid(i, 1) == "\"" || str.mid(i, 1) == "\'") { nStart = i; nState = InsideCString; } else { QString strKeyword = getKeyword(i, str); if (!strKeyword.isEmpty()) { setFormat(i, strKeyword.length(), Qt::white); i += strKeyword.length() - 1; } } } } if (nState == InsideCStyleComment) { setFormat(nStart, str.length() - nStart, Qt::darkGray); } if (nState == InsideCString) { setFormat(nStart, str.length() - nStart, Qt::cyan); } setCurrentBlockState(nState); }
unsigned int SyntaxHighlighter::buildCodeDoc(QString) { if(previousBlockState()==CodeDoc) setCurrentBlockState(CodeDoc); setFormat(startIndex,lexerleng,codeDocFormat); return YY_CONTINUE; }
void SyntaxHighlighter::buildCodeDoc() { if(previousBlockState()==CodeDoc) setCurrentBlockState(CodeDoc); setFormat(startIndex,lexerleng,codeDocFormat); startIndex+=lexerleng; }
void CodeSyntaxHighlither::highlightBlock(const QString& text) { for(const CodeSyntaxHighlightRule& rule : m_CodeHighlightingRules) { QRegExp expression(rule.m_Pattern); int32_t index = expression.indexIn(text); while(index >= 0) { int32_t length = expression.matchedLength(); setFormat(index, length, rule.m_Format); index = expression.indexIn(text, index + length); } } setCurrentBlockState(0); int32_t startIndex = 0; if(previousBlockState() != 1) { startIndex = m_CommentStartExpression.indexIn(text); } while(startIndex >= 0) { int32_t endIndex = m_CommentEndExpression.indexIn(text, startIndex); int32_t commentLength = 0; if(endIndex == -1) { setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex + m_CommentEndExpression.matchedLength(); } setFormat(startIndex, commentLength, m_MultiLineCommentFormat); startIndex = m_CommentStartExpression.indexIn(text, startIndex + commentLength); } }
void SyntaxHighlighter::highlightBlock(const QString &text) { if(languageSet) { // stops syntax highlight code running when searching for reg exp query // search line for any autocomplete suggestions autoCompleteSuggestions += searchInputForAutocompleteRules(text); foreach (const SyntaxHighlightingRuleSet::HighlightingRule rule, ruleSet->highlightingRules) { QRegExp expression(rule.pattern); int index = expression.indexIn(text); while (index >= 0) { int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(text, index + length); } } setCurrentBlockState(0); int startIndex = 0; if (previousBlockState() != 1) startIndex = ruleSet->commentStartExpression.indexIn(text); while (startIndex >= 0) { int endIndex = ruleSet->commentEndExpression.indexIn(text, startIndex); int commentLength; if (endIndex == -1) { setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex + ruleSet->commentEndExpression.matchedLength(); } setFormat(startIndex, commentLength, ruleSet->multiLineCommentFormat); startIndex = ruleSet->commentStartExpression.indexIn(text, startIndex + commentLength); } // if the search box is populated with an expression if(searchExpression.pattern() != "") { highlightSearchExpression(searchExpression, text); } } }
void MercurialSubmitHighlighter::highlightBlock(const QString &text) { // figure out current state State state = static_cast<State>(previousBlockState()); if (text.startsWith(QLatin1String("HG:"))) { setFormat(0, text.size(), formatForCategory(Format_Comment)); setCurrentBlockState(state); return; } if (state == None) { if (text.isEmpty()) { setCurrentBlockState(state); return; } state = Header; } else if (state == Header) { state = Other; } setCurrentBlockState(state); // Apply format. switch (state) { case None: break; case Header: { QTextCharFormat charFormat = format(0); charFormat.setFontWeight(QFont::Bold); setFormat(0, text.size(), charFormat); break; } case Other: // Format key words ("Task:") italic if (m_keywordPattern.indexIn(text, 0, QRegExp::CaretAtZero) == 0) { QTextCharFormat charFormat = format(0); charFormat.setFontItalic(true); setFormat(0, m_keywordPattern.matchedLength(), charFormat); } break; } }
void LatexFileType::highlightBlock(const QString &text) { //comments int comInd = text.indexOf('%'); while (comInd > 0 && text.at(comInd - 1) == '\\') comInd = text.indexOf('%', comInd + 1); clearCurrentBlockSkipSegments(); addCurrentBlockSkipSegment(comInd); if (comInd >= 0) setFormat(comInd, text.length() - comInd, QColor(Qt::darkGray)); QString ntext = text.left(comInd); //commands QRegExp rx("(\\\\[a-zA-Z]*|\\\\#|\\\\\\$|\\\\%|\\\\&|\\\\_|\\\\\\{|\\\\\\})+"); int pos = rx.indexIn(ntext); while (pos >= 0) { int len = rx.matchedLength(); setFormat(pos, len, QColor(Qt::red).lighter(70)); pos = rx.indexIn(ntext, pos + len); } //multiline (math mode) setCurrentBlockState(!ntext.isEmpty() ? 0 : previousBlockState()); int startIndex = 0; bool firstIsStart = false; if (previousBlockState() != 1) { startIndex = indexOf(ntext, "$"); firstIsStart = true; } while (startIndex >= 0) { int endIndex = indexOf(ntext, "$", startIndex + (firstIsStart ? 1 : 0)); int commentLength; if (endIndex == -1) { setCurrentBlockState(1); commentLength = ntext.length() - startIndex; } else { commentLength = endIndex - startIndex + 1; } setFormat(startIndex, commentLength, QColor(Qt::darkGreen)); startIndex = indexOf(ntext, "$", startIndex + commentLength); } }
void SmkMarkHighlighter::_aux_multiBlockMatch( const QString& text, const QString& bgnFlag, const QString& endFlag, const QTextCharFormat& format, const unsigned field ) { if(previousBlockState() == -1) return; setCurrentBlockState(currentBlockState() & (~field)); if(previousBlockState() & field) { int endid = text.indexOf(endFlag, 0); if(endid != -1) { // we find a endFlag setFormat(0, endid+endFlag.length(), format); } else { // we do not find a endFlag, mark this line and go on setFormat(0, text.length(), format); // if(previousBlockState() != -1) setCurrentBlockState(currentBlockState() | field); } } else { int bgnid = text.indexOf(bgnFlag, 0); while(bgnid != -1) { int endid = text.indexOf(endFlag, bgnid+bgnFlag.length()); if(endid != -1) { // we find a endFlag setFormat(bgnid, endid+endFlag.length()-bgnid, format); bgnid = text.indexOf(bgnFlag, endid+endFlag.length()); } else { // we do not find a endFlag, mark this line and go on setFormat(bgnid, text.length()-bgnid, format); setCurrentBlockState(currentBlockState() | field); break; } }//while(... }//if..else... }
void QScriptHighlighter::highlightBlock(const QString & txt) { for(const HighlightingRule & rule : highlightingRules) { QRegExp expression(rule.pattern); int index = expression.indexIn(txt); while(index >= 0) { const int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(txt, index + length); } } setCurrentBlockState(0); int startIndex = 0; if(previousBlockState() != 1) startIndex = commentStartExpression.indexIn(txt); while(startIndex >= 0) { int endIndex = commentEndExpression.indexIn(txt, startIndex); int commentLength; if(endIndex == -1) { setCurrentBlockState(1); commentLength = txt.length() - startIndex; } else commentLength = endIndex - startIndex + commentEndExpression.matchedLength(); setFormat(startIndex, commentLength, multiLineCommentFormat); startIndex = commentStartExpression.indexIn(txt, startIndex + commentLength); } }
void MIPS32SyntaxHighlighter::highlightBlock(QString const &text){ refreshEditor(); for(int i=0; i<highlightingRules.size(); i++){ HighlightingRule rule = highlightingRules[i]; int start = rule.regex.indexIn(text); while(start >= 0){ int len = rule.regex.matchedLength(); setFormat(start, len, rule.format); start = rule.regex.indexIn(text, start + len); } } setCurrentBlockState(0); }
void OSyntaxHighlighter :: highlightBlock (const QString &qscText ) { logical term = NO; int iStart = 0; setCurrentBlockState(0); if(previousBlockState() > 0) // in block FindEndBlock(qscText,iStart,elements[previousBlockState()]); if(iStart>=0) FindElements(qscText,iStart); }