Skip to content

Instantly share code, notes, and snippets.

@klemens-morgenstern
Created October 22, 2016 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klemens-morgenstern/c2fd32e0c0a46a225c6174f2471d947b to your computer and use it in GitHub Desktop.
Save klemens-morgenstern/c2fd32e0c0a46a225c6174f2471d947b to your computer and use it in GitHub Desktop.
/*
* ChaiScriptSyntaxHighlighter.hpp
*
* Created on: 21.10.2016
* Author: klemens.morgenstern
*/
#ifndef WIDGETS_CHAISCRIPTSYNTAXHIGHLIGHTER_HPP_
#define WIDGETS_CHAISCRIPTSYNTAXHIGHLIGHTER_HPP_
#include <QSyntaxHighlighter>
namespace widgets {
class ChaiScriptRule
{
public:
ChaiScriptRule(const QString &patternStr, int n, const QTextCharFormat &matchingFormat)
{
originalRuleStr = patternStr;
pattern = QRegExp(patternStr);
nth = n;
format = matchingFormat;
}
QString originalRuleStr;
QRegExp pattern;
int nth;
QTextCharFormat format;
};
//! Implementation of highlighting for Python code.
class ChaiScriptSyntaxHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
ChaiScriptSyntaxHighlighter(QTextDocument *parent = 0);
protected:
void highlightBlock(const QString &text);
private:
QStringList keywords;
QStringList operators;
QStringList braces;
QHash<QString, QTextCharFormat> basicStyles;
void initializeRules();
//! Highlighst multi-line strings, returns true if after processing we are still within the multi-line section.
bool matchMultiline(const QString &text, const QRegExp &delimiter, const int inState, const QTextCharFormat &style);
const QTextCharFormat getTextCharFormat(const QString &colorName, const QString &style = QString());
QList<ChaiScriptRule> rules;
};
} /* namespace widgets */
#endif /* WIDGETS_CHAISCRIPTSYNTAXHIGHLIGHTER_HPP_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment