1 #ifndef HIGHLIGHTER_H
2 #define HIGHLIGHTER_H
3 
4 #include "core/Cutter.h"
5 
6 #include <QSyntaxHighlighter>
7 #include <QHash>
8 #include <QTextCharFormat>
9 #include <QRegularExpression>
10 
11 class QTextDocument;
12 class MainWindow;
13 
14 class Highlighter : public QSyntaxHighlighter
15 {
16     Q_OBJECT
17 
18 public:
19     Highlighter(QTextDocument *parent = nullptr);
20 
21 protected:
22     void highlightBlock(const QString &text);
23 
24 private:
25     CutterCore *core;
26 
27     struct HighlightingRule {
28         QRegularExpression pattern;
29         QTextCharFormat format;
30     };
31     QVector<HighlightingRule> highlightingRules;
32 
33     QRegularExpression commentStartRegularExpression;
34     QRegularExpression commentEndRegularExpression;
35 
36     QTextCharFormat keywordFormat;
37     QTextCharFormat regFormat;
38     QTextCharFormat classFormat;
39     QTextCharFormat singleLineCommentFormat;
40     QTextCharFormat multiLineCommentFormat;
41     QTextCharFormat quotationFormat;
42     QTextCharFormat functionFormat;
43 };
44 
45 #endif   // HIGHLIGHTER_H
46