#pragma once #include #include #include #include class SyntaxHighlighter : public QSyntaxHighlighter { Q_OBJECT public: explicit SyntaxHighlighter(QTextDocument *parent = nullptr); ~SyntaxHighlighter(); void setLanguage(const QString &language); QString language() const; protected: void highlightBlock(const QString &text) override; private: struct HighlightingRule { QRegularExpression pattern; QTextCharFormat format; }; QVector m_highlightingRules; void setupCppHighlighting(); void setupCHighlighting(); void setupCommonRules(); QTextCharFormat m_keywordFormat; QTextCharFormat m_classFormat; QTextCharFormat m_singleLineCommentFormat; QTextCharFormat m_multiLineCommentFormat; QTextCharFormat m_quotationFormat; QTextCharFormat m_functionFormat; QTextCharFormat m_numberFormat; QTextCharFormat m_preprocessorFormat; QRegularExpression m_commentStartExpression; QRegularExpression m_commentEndExpression; QString m_language; };