-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptSyntaxHighlighter.h
62 lines (53 loc) · 1.36 KB
/
ScriptSyntaxHighlighter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include <QSyntaxHighlighter>
#include <QTextDocument>
#include <QRegularExpression>
#include "ScriptColorScheme.h"
#include "ScriptKeyword.h"
// Note: only small subset of ECMA-262 syntax is supported
class ScriptSyntaxHighlighter: public QSyntaxHighlighter
{
Q_OBJECT
public:
explicit ScriptSyntaxHighlighter(QTextDocument* a_parent = nullptr);
protected:
void highlightBlock(const QString& a_text) override;
private:
void initNumbers();
void initStrings();
void initKeywords();
void initFunctions();
void initPunctuators();
void initSingleLineComments();
void initMultilineComments();
void initApiArguments();
void initApiSoundProperties();
void highlightPunctuators(const QString& a_text);
void highlightByRules(const QString& a_rext);
void highlightMultilineComments(const QString& a_text);
struct HighlightingRule {
QTextCharFormat format;
QRegularExpression pattern;
};
QList<HighlightingRule> m_rules;
struct {
QRegularExpression start;
QRegularExpression end;
QTextCharFormat format;
} m_multiline_comment_rule;
struct {
QTextCharFormat format;
const QStringList punctuators = {
"{","}","(",")","[","]",
".",";",",",
"<",">","<=",">=","==","!=",
"+","-","*","/","%",
"++","--",
"<<",">>",
"&","|","^","!","~",
"&&","||",
"?",":",
"=","+=","-=","*=","/*","%=",
};
} m_punctuator_rule;
};