2017-09-16 16:04:29 +03:00
|
|
|
#ifndef LRSCRIPTHIGHLIGHTER_H
|
|
|
|
#define LRSCRIPTHIGHLIGHTER_H
|
|
|
|
|
2020-11-05 22:31:16 +03:00
|
|
|
#include <QSet>
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QSyntaxHighlighter>
|
2017-09-16 16:04:29 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
namespace LimeReport {
|
2017-09-16 16:04:29 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
enum ParenthesisType {
|
|
|
|
LeftParenthesis,
|
|
|
|
RightParenthesis,
|
|
|
|
ParenthesisTypeCount
|
|
|
|
};
|
2017-09-19 19:05:38 +03:00
|
|
|
|
|
|
|
#define PARENHEIS_COUNT 3
|
2024-09-04 17:31:16 +03:00
|
|
|
const QChar parenthesisCharacters[ParenthesisTypeCount][PARENHEIS_COUNT]
|
|
|
|
= { { '(', '{', '[' }, { ')', '}', ']' } };
|
2017-09-19 19:05:38 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
struct ParenthesisInfo {
|
2017-09-19 19:05:38 +03:00
|
|
|
char character;
|
|
|
|
int position;
|
|
|
|
};
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
class TextBlockData: public QTextBlockUserData {
|
2017-09-19 19:05:38 +03:00
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
TextBlockData() { }
|
2018-03-07 19:46:23 +03:00
|
|
|
~TextBlockData();
|
2024-09-04 17:31:16 +03:00
|
|
|
QVector<ParenthesisInfo*> parentheses();
|
|
|
|
void insert(ParenthesisInfo* info);
|
2017-09-19 19:05:38 +03:00
|
|
|
|
|
|
|
private:
|
2024-09-04 17:31:16 +03:00
|
|
|
QVector<ParenthesisInfo*> m_parentheses;
|
2017-09-19 19:05:38 +03:00
|
|
|
};
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
class ScriptHighlighter: QSyntaxHighlighter {
|
2017-09-16 16:04:29 +03:00
|
|
|
public:
|
2017-09-19 19:05:38 +03:00
|
|
|
ScriptHighlighter(QTextDocument* parent);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
2017-09-16 16:04:29 +03:00
|
|
|
protected:
|
|
|
|
void highlightBlock(const QString& text);
|
2017-09-19 19:05:38 +03:00
|
|
|
enum ScriptFormats {
|
2024-09-04 17:31:16 +03:00
|
|
|
NumberFormat,
|
|
|
|
StringFormat,
|
|
|
|
KeywordFormat,
|
|
|
|
CommentFormat,
|
|
|
|
FormatsCount
|
2017-09-19 19:05:38 +03:00
|
|
|
};
|
|
|
|
QTextCharFormat m_formats[FormatsCount];
|
|
|
|
bool isKeyWord(const QString& word);
|
2024-09-04 17:31:16 +03:00
|
|
|
void createParentheisisInfo(const char& literal, TextBlockData* data, const QString& text);
|
|
|
|
|
2020-09-17 10:35:48 +03:00
|
|
|
private:
|
|
|
|
QSet<QString> m_keywords;
|
2017-09-16 16:04:29 +03:00
|
|
|
};
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
} // namespace LimeReport
|
2017-09-16 16:04:29 +03:00
|
|
|
#endif // LRSCRIPTHIGHLIGHTER_H
|