Ejemplo n.º 1
0
// 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);
}
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);


}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
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);
    }
}
Ejemplo n.º 5
0
    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);
        }
    }
Ejemplo n.º 6
0
void Highlighter::highlightBlock(const QString &text)
{
    int initialState = previousBlockState();
    if (initialState == -1)
        initialState = 0;
    setCurrentBlockState(highlightLine(text, initialState));
}
Ejemplo n.º 7
0
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);
        }
    }
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
unsigned int SyntaxHighlighter::buildCodeDoc(QString)
{
	if(previousBlockState()==CodeDoc)
		setCurrentBlockState(CodeDoc);

	setFormat(startIndex,lexerleng,codeDocFormat);
	return YY_CONTINUE;
}
Ejemplo n.º 11
0
void SyntaxHighlighter::buildCodeDoc()
{
	if(previousBlockState()==CodeDoc)
		setCurrentBlockState(CodeDoc);

	setFormat(startIndex,lexerleng,codeDocFormat);
	startIndex+=lexerleng;
}
Ejemplo n.º 12
0
int QScriptHighlighter::onBlockStart()
{
    int state = 0;
    int previousState = previousBlockState();
    if (previousState != -1)
        state = previousState;
    return state;
}
Ejemplo n.º 13
0
/** 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();
}
Ejemplo n.º 14
0
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);
    }
}
Ejemplo n.º 15
0
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...
}
Ejemplo n.º 16
0
/** 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();
}
Ejemplo n.º 17
0
void SyntaxHighligther::highlightBlock(const QString& text) {
    setFormat(0, text.size(), defaultFormat_);
    std::vector<SyntaxFormater*>::iterator it;

    for (it = formaters_.begin(); it != formaters_.end(); ++it) {
        SyntaxFormater::Result res = (*it)->eval(text, previousBlockState());

        for (size_t i = 0; i < res.start.size(); i++) {
            setFormat(res.start[i], res.length[i], *res.format);
            setCurrentBlockState(res.outgoingState);
        }
    }
}
Ejemplo n.º 18
0
	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);
			}
		}
	}
Ejemplo n.º 19
0
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);
    }

}
Ejemplo n.º 20
0
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 SyntaxHighlighter::highlightBlock(const QString &text)
{
  //Do the main block highlighting.
  highlightSubBlock(text, 0, previousBlockState());

  //Run the set of inline rules.
  foreach (const HighlightingRule &rule, hlRules)
    {
      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);
      }
    }
void OSyntaxHighlighter :: FindEndBlock (const QString &qscText, int32 &riStart, SyntaxElement &rsyntaxelement )
{
  int                        iLength = 0;

  if(FindElement(qscText,riStart,rsyntaxelement.rxEnd)){
    riStart += rsyntaxelement.rxEnd.cap(0).length();
    iLength = riStart;
  }
  else{
    iLength = qscText.length();
    setCurrentBlockState(previousBlockState());
  }
  AddFormatRange(rsyntaxelement.syntaxclass,0,iLength);



}
void SyntaxHighlighter::highlightBlock(const QString &text)
{
    int currentBlockState = STATE_NORMAL;
    QTextCharFormat f;
    f.setFontItalic(!m_approved);
    setFormat(0, text.length(), f);

    tagFormat.setFontItalic(!m_approved);
    //if (fromDocbook)
    {
        int startIndex = STATE_NORMAL;
        if (previousBlockState() != STATE_TAG)
            startIndex = text.indexOf('<');

        while (startIndex >= 0)
        {
            int endIndex = text.indexOf('>', startIndex);
            int commentLength;
            if (endIndex == -1)
            {
                currentBlockState = STATE_TAG;
                commentLength = text.length() - startIndex;
            }
            else
            {
                commentLength = endIndex - startIndex
                                +1/*+ commentEndExpression.matchedLength()*/;
            }
            setFormat(startIndex, commentLength, tagFormat);
            startIndex = text.indexOf('<', startIndex + commentLength);
        }
    }

    foreach (const HighlightingRule &rule, highlightingRules)
    {
        QRegExp expression(rule.pattern);
        int index = expression.indexIn(text);
        while (index >= 0)
        {
            int length = expression.matchedLength();
            QTextCharFormat f=rule.format;
            f.setFontItalic(!m_approved);
            setFormat(index, length, f);
            index = expression.indexIn(text, index + length);
        }
    }
void QScriptSyntaxHighlighter::highlightBlock(const QString &text)
{

    // states
    enum States { StateStandard, StateCommentStart1, StateCCommentStart2,
                  StateScriptCommentStart2, StateCComment, StateScriptComment, StateCCommentEnd1,
                  StateCCommentEnd2, StateStringStart, StateString, StateStringEnd,
                  StateString2Start, StateString2, StateString2End,
                  StateNumber, StatePreProcessor, NumStates  };

    // tokens
    enum Tokens { InputAlpha, InputNumber, InputAsterix, InputSlash, InputParen,
                  InputSpace, InputHash, InputQuotation, InputApostrophe, InputSep, NumTokens };

    static uchar table[NumStates][NumTokens] = {
        { StateStandard,      StateNumber,     StateStandard,       StateCommentStart1,    StateStandard,   StateStandard,   StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateStandard
        { StateStandard,      StateNumber,   StateCCommentStart2, StateScriptCommentStart2, StateStandard,   StateStandard,   StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateCommentStart1
        { StateCComment,      StateCComment,   StateCCommentEnd1,   StateCComment,         StateCComment,   StateCComment,   StateCComment,     StateCComment,    StateCComment,     StateCComment }, // StateCCommentStart2
        { StateScriptComment,    StateScriptComment, StateScriptComment,     StateScriptComment,       StateScriptComment, StateScriptComment, StateScriptComment,   StateScriptComment,  StateScriptComment,   StateScriptComment }, // ScriptCommentStart2
        { StateCComment,      StateCComment,   StateCCommentEnd1,   StateCComment,         StateCComment,   StateCComment,   StateCComment,     StateCComment,    StateCComment,     StateCComment }, // StateCComment
        { StateScriptComment,    StateScriptComment, StateScriptComment,     StateScriptComment,       StateScriptComment, StateScriptComment, StateScriptComment,   StateScriptComment,  StateScriptComment,   StateScriptComment }, // StateScriptComment
        { StateCComment,      StateCComment,   StateCCommentEnd1,   StateCCommentEnd2,     StateCComment,   StateCComment,   StateCComment,     StateCComment,    StateCComment,     StateCComment }, // StateCCommentEnd1
        { StateStandard,      StateNumber,     StateStandard,       StateCommentStart1,    StateStandard,   StateStandard,   StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateCCommentEnd2
        { StateString,        StateString,     StateString,         StateString,           StateString,     StateString,     StateString,       StateStringEnd,   StateString,       StateString }, // StateStringStart
        { StateString,        StateString,     StateString,         StateString,           StateString,     StateString,     StateString,       StateStringEnd,   StateString,       StateString }, // StateString
        { StateStandard,      StateStandard,   StateStandard,       StateCommentStart1,    StateStandard,   StateStandard,   StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateStringEnd
        { StateString2,       StateString2,    StateString2,        StateString2,          StateString2,    StateString2,    StateString2,      StateString2,     StateString2End,   StateString2 }, // StateString2Start
        { StateString2,       StateString2,    StateString2,        StateString2,          StateString2,    StateString2,    StateString2,      StateString2,     StateString2End,   StateString2 }, // StateString2
        { StateStandard,      StateStandard,   StateStandard,       StateCommentStart1,    StateStandard,   StateStandard,   StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateString2End
        { StateNumber,        StateNumber,     StateStandard,       StateCommentStart1,    StateStandard,   StateStandard,   StatePreProcessor, StateStringStart, StateString2Start, StateStandard }, // StateNumber
        { StatePreProcessor,  StateStandard,   StateStandard,       StateCommentStart1,    StateStandard,   StateStandard,   StatePreProcessor, StateStringStart, StateString2Start, StateStandard } // StatePreProcessor
    };

    QString buffer;
    buffer.reserve(text.length());

    QTextCharFormat emptyFormat;

    int state = StateStandard;
    int braceDepth = 0;
    const int previousState = previousBlockState();
    if (previousState != -1) {
        state = previousState & 0xff;
        braceDepth = previousState >> 8;
    }
Ejemplo n.º 25
0
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);
	}
}
Ejemplo n.º 26
0
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);
        }
    }
}
Ejemplo n.º 27
0
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;
    }
}
Ejemplo n.º 28
0
void LuaHighlighter::highlightBlock(const QString &text)
{
    setCurrentBlockState(BS_Dummy);
    MyTextBlockUserData* p = static_cast<MyTextBlockUserData*>(currentBlockUserData());
    if(p){
        p->clear();
    }else{
        p = new MyTextBlockUserData();
        setCurrentBlockUserData(p);
    }
    int offset = 0;
    int prevState = previousBlockState();
    //*
    if (prevState != BS_Dummy && prevState < BS_LastState && prevState>0){
        HighlightingRule prevRule = highlightingRules.at(prevState);
        int len = matchBlockEnd(text, offset, prevRule);
        setFormat(offset, len, prevRule);
        offset += len;
    }
    //*/

    //foreach (const HighlightingRule &rule, highlightingRules) {
    //QRegExp expression(rule.pattern);
    //int index = expression.indexIn(text, offset);
    while(offset < text.length()){
        HighlightingRule rule;
        int matchedLength = 0;
        int index = matchPatten(text,offset,rule,matchedLength);
        while (index >= 0) {
            int length = matchedLength;
            if(rule.blockState != BS_Dummy){
                length = matchBlockEnd(text, index+matchedLength, rule);
                length += matchedLength;
            }
            setFormat(index, length, rule);
            offset = index + length;
            index = matchPatten(text,offset,rule,matchedLength);
        }
        if(index == -1)break;
    }
}
Ejemplo n.º 29
0
void SyntaxHighlighter::highlightBlock(const QString& text)
{
	startIndex=0;
	lexerinit(this,NULL,text,false);

	//Force lexer into correct state
	switch(previousBlockState()) {
	case Initial:
		lexerbegin();
		break;
	case Comment:
		lexercomment();
		break;
	case CodeDoc:
		lexercodedoc();
		break;
	}

	while(nextToken());

}
Ejemplo n.º 30
0
void SyntaxHighlighter::highlightBlock(const QString& text)
{
    TextBlockData *blockData = static_cast<TextBlockData*>(currentBlockUserData());
    if(!blockData) {
        blockData = new TextBlockData;
        blockData->tokens.reserve(8);
        setCurrentBlockUserData(blockData);
    }
    else {
        blockData->tokens.clear();
    }

    int previousState = previousBlockState();
    if (previousState == -1)
        previousState = ScLexer::InCode;

    ScLexer lexer( text, 0, previousState );

    while (lexer.offset() < text.size()) {
        switch (lexer.state()) {
        case ScLexer::InCode:
            highlightBlockInCode(lexer);
            break;

        case ScLexer::InString:
            highlightBlockInString(lexer);
            break;

        case ScLexer::InSymbol:
            highlightBlockInSymbol(lexer);
            break;

        default:
            if(lexer.state() >= ScLexer::InComment)
                highlightBlockInComment(lexer);
        }
    }

    setCurrentBlockState( lexer.state() );
}