| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef JSSYNTAXHIGHLIGHTER_H |
| 4 | #define JSSYNTAXHIGHLIGHTER_H |
| 5 | |
| 6 | #include <QRegularExpression> |
| 7 | #include <QSyntaxHighlighter> |
| 8 | |
| 9 | class JsSyntaxHighlighter : public QSyntaxHighlighter { |
| 10 | Q_OBJECT |
| 11 | |
| 12 | public: |
| 13 | JsSyntaxHighlighter(QTextDocument* parent); |
| 14 | |
| 15 | QStringList jsKeywords() const; |
| 16 | |
| 17 | protected: |
| 18 | virtual void highlightBlock(const QString& text) override; |
| 19 | |
| 20 | private: |
| 21 | struct HighlightingRule { |
| 22 | QRegularExpression m_pattern; |
| 23 | QTextCharFormat m_format; |
| 24 | }; |
| 25 | |
| 26 | QList<HighlightingRule> m_highlightingRules; |
| 27 | |
| 28 | QRegularExpression m_commentStartExpression; |
| 29 | QRegularExpression m_commentEndExpression; |
| 30 | |
| 31 | QTextCharFormat m_keywordFormat; |
| 32 | QTextCharFormat m_classFormat; |
| 33 | QTextCharFormat m_singleLineCommentFormat; |
| 34 | QTextCharFormat m_multiLineCommentFormat; |
| 35 | QTextCharFormat m_quotationFormat; |
| 36 | QTextCharFormat m_functionFormat; |
| 37 | }; |
| 38 | |
| 39 | #endif // JSSYNTAXHIGHLIGHTER_H |