blob: 093ca52a201fd299be2d48b45d633d9deb96d046 (
plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
//===========================================
// Lumina-DE source code
// Copyright (c) 2015, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "syntaxSupport.h"
QStringList Custom_Syntax::availableRules(){
QStringList avail;
avail << "C++";
avail << "Python";
return avail;
}
QString Custom_Syntax::ruleForFile(QString filename){
QString suffix = filename.section(".",-1);
if(suffix=="cpp" || suffix=="hpp" || suffix=="c" || suffix=="h"){ return "C++"; }
return "";
}
void Custom_Syntax::loadRules(QString type){
//NOTE: the "multiLineComment
rules.clear();
splitrules.clear();
if(type=="C++"){
//Keywords (standard C/C++/Qt definitions)
QStringList keywords;
keywords << "char" << "class" << "const" << "double" << "enum" << "explicit" << "friend" << "inline" \
<< "int" << "long" << "namespace" << "operator" << "private" << "protected" << "public" \
<< "short" << "signals" << "signed" << "slots" << "static" << "struct" << "template" \
<< "typedef" << "typename" << "union" << "unsigned" << "virtual" << "void" << "volatile";
SyntaxRule rule;
rule.format.setForeground(Qt::darkBlue);
rule.format.setFontWeight(QFont::Bold);
for(int i=0; i<keywords.length(); i++){
rule.pattern = QRegExp("\\b"+keywords[i]+"\\b"); //turn each keyword into a QRegExp and insert the rule
rules << rule;
}
//Class Names
rule.format.setForeground(Qt::darkMagenta);
rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
rules << rule;
//Quotes
rule.format.setForeground(Qt::red);
rule.format.setFontWeight(QFont::Normal);
rule.pattern = QRegExp("\".*\"");
rules << rule;
//Functions
rule.format.setForeground(Qt::blue);
rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
rules << rule;
//Comment (single line)
rule.format.setForeground(Qt::green);
rule.pattern = QRegExp("//[^\n]*");
rules << rule;
//Comment (multi-line)
SyntaxRuleSplit srule;
srule.format = rule.format; //re-use the single-line comment format
srule.startPattern = QRegExp("/\\*");
srule.endPattern = QRegExp("\\*/");
splitrules << srule;
}else if(type=="Python"){
//Keywords
QStringList keywords;
keywords << "and" << "as" << "assert" << "break" << "class" << "continue" << "def" << "del" \
<< "elif" << "else" << "except" << "exec" << "finally" << "for" << "from" \
<< "global" << "if" << "import" << "in" << "is" << "lambda" << "not" \
<< "or" << "pass" << "print" << "raise" << "return" << "try" << "while" << "with" << "yield";
SyntaxRule rule;
rule.format.setForeground(Qt::darkBlue);
rule.format.setFontWeight(QFont::Bold);
for(int i=0; i<keywords.length(); i++){
rule.pattern = QRegExp("\\b"+keywords[i]+"\\b"); //turn each keyword into a QRegExp and insert the rule
rules << rule;
}
//Class Names
//rule.format.setForeground(Qt::darkMagenta);
//rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
//rules << rule;
//Quotes
rule.format.setForeground(Qt::red);
rule.format.setFontWeight(QFont::Normal);
rule.pattern = QRegExp("\".*\"");
rules << rule;
//Functions
rule.format.setForeground(Qt::blue);
rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
rules << rule;
//Comment (single line)
rule.format.setForeground(Qt::green);
rule.pattern = QRegExp("#[^\n]*");
rules << rule;
//Comment (multi-line)
//SyntaxRuleSplit srule;
//srule.format = rule.format; //re-use the single-line comment format
//srule.startPattern = QRegExp("/\\*");
//srule.endPattern = QRegExp("\\*/");
//splitrules << srule;
}
}
|