2017-12-15 10:52:47 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QTextDocument>
|
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QTextCharFormat>
|
|
|
|
|
|
|
|
|
|
|
|
class SyntaxHighlighter : public QSyntaxHighlighter
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
SyntaxHighlighter(QTextDocument *parent = nullptr);
|
|
|
|
virtual ~SyntaxHighlighter() = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void highlightBlock(const QString &text) override;
|
|
|
|
|
|
|
|
private:
|
2018-03-21 20:32:32 +00:00
|
|
|
struct HighlightingRule {
|
2017-12-15 10:52:47 +00:00
|
|
|
QRegularExpression pattern;
|
|
|
|
QTextCharFormat format;
|
|
|
|
};
|
|
|
|
|
|
|
|
QVector<HighlightingRule> highlightingRules;
|
|
|
|
|
|
|
|
QRegularExpression commentStartExpression;
|
|
|
|
QRegularExpression commentEndExpression;
|
|
|
|
|
|
|
|
QTextCharFormat multiLineCommentFormat;
|
|
|
|
};
|