Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
lua_syntax_highlighter.h
Go to the documentation of this file.
1
9
10#ifndef LUA_SYNTAX_HIGHLIGHTER_H
11#define LUA_SYNTAX_HIGHLIGHTER_H
12
14
15#include <QColor>
16#include <QHash>
17#include <QRegularExpression>
18#include <QString>
19#include <QSyntaxHighlighter>
20#include <QTextCharFormat>
21#include <QVector>
22#include <QtGlobal>
23
24class QTextDocument;
25
35class LuaSyntaxHighlighter : public QSyntaxHighlighter
36{
37 public:
39 explicit LuaSyntaxHighlighter(QTextDocument *parent);
40
42 void updateColors();
43
49 void setColors(const QHash<ThemeManager::ThemeToken, QColor> &colors);
50
51 protected:
53 void highlightBlock(const QString &text) override;
54
55 private:
59 struct Rule
60 {
61 QRegularExpression pattern;
62 QTextCharFormat format;
63 };
64
65
66 QVector<Rule> rules_;
67 QTextCharFormat stringFormat_;
68 QTextCharFormat commentFormat_;
69 QRegularExpression singleLineComment_;
70 QHash<ThemeManager::ThemeToken, QColor> colors_;
71
73 QColor color(ThemeManager::ThemeToken token) const;
74
76 bool highlightLongBlock(const QString &text, bool isComment, bool continuingPrevious, qint32 eqCountFromState,
77 qint32 &nextStateEqCount);
79 qint32 findLongBlockStart(const QString &text, qint32 from, bool isComment, qint32 &eqCount,
80 qint32 &tokenLength) const;
82 qint32 findLongBlockEnd(const QString &text, qint32 from, qint32 eqCount) const;
83
85 void buildRules();
86};
87
88#endif // LUA_SYNTAX_HIGHLIGHTER_H
void highlightBlock(const QString &text) override
Apply highlighting to a single text block.
Definition lua_syntax_highlighter.cpp:95
void updateColors()
Rebuild the rule set from the current theme colours and rehighlight.
Definition lua_syntax_highlighter.cpp:32
LuaSyntaxHighlighter(QTextDocument *parent)
Build the rule set from the current theme and bind to parent's document.
Definition lua_syntax_highlighter.cpp:26
void setColors(const QHash< ThemeManager::ThemeToken, QColor > &colors)
Use colors instead of the live theme, then rehighlight.
Definition lua_syntax_highlighter.cpp:38