2015-04-22 19:33:53 +02:00
|
|
|
#ifndef JAVASCRIPTHIGHLIGHTER_H
|
|
|
|
#define JAVASCRIPTHIGHLIGHTER_H
|
|
|
|
|
2018-08-15 22:23:57 +02:00
|
|
|
#include <QRegularExpression>
|
2015-04-22 19:33:53 +02:00
|
|
|
#include <QSyntaxHighlighter>
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2018-03-07 01:18:01 +01:00
|
|
|
class JavaScriptHighlighter : public QSyntaxHighlighter {
|
2015-04-22 19:33:53 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
JavaScriptHighlighter(QTextDocument *parent = nullptr);
|
|
|
|
|
|
|
|
protected:
|
2018-08-15 22:23:57 +02:00
|
|
|
void highlightBlock(const QString &text) override;
|
2015-04-22 19:33:53 +02:00
|
|
|
|
|
|
|
private:
|
2018-03-07 01:18:01 +01:00
|
|
|
struct HighlightingRule {
|
2018-08-15 22:23:57 +02:00
|
|
|
QRegularExpression pattern;
|
2015-04-22 19:33:53 +02:00
|
|
|
QTextCharFormat format;
|
|
|
|
};
|
|
|
|
QVector<HighlightingRule> m_highlightingRules;
|
|
|
|
|
2018-08-15 22:23:57 +02:00
|
|
|
QRegularExpression m_commentStartExpression;
|
|
|
|
QRegularExpression m_commentEndExpression;
|
2015-04-22 19:33:53 +02:00
|
|
|
|
|
|
|
QTextCharFormat m_keywordFormat;
|
|
|
|
QTextCharFormat m_classFormat;
|
|
|
|
QTextCharFormat m_singleLineCommentFormat;
|
|
|
|
QTextCharFormat m_multiLineCommentFormat;
|
2018-08-15 22:23:57 +02:00
|
|
|
QTextCharFormat m_stringFormat;
|
|
|
|
QTextCharFormat m_regexFormat;
|
2015-04-22 19:33:53 +02:00
|
|
|
QTextCharFormat m_functionFormat;
|
|
|
|
};
|
|
|
|
|
2018-03-07 01:18:01 +01:00
|
|
|
} // namespace QtGui
|
2015-04-22 19:33:53 +02:00
|
|
|
|
|
|
|
#endif // JAVASCRIPTHIGHLIGHTER_H
|