Changeset View
Changeset View
Standalone View
Standalone View
src/backends/R/rhighlighter.cpp
Show All 36 Lines | 36 | { | |||
---|---|---|---|---|---|
37 | addKeywords(RKeywords::instance()->keywords()); | 37 | addKeywords(RKeywords::instance()->keywords()); | ||
38 | 38 | | |||
39 | foreach (const QString& s, operators_list) | 39 | foreach (const QString& s, operators_list) | ||
40 | operators.append(QRegExp(s)); | 40 | operators.append(QRegExp(s)); | ||
41 | foreach (const QString& s, specials_list) | 41 | foreach (const QString& s, specials_list) | ||
42 | specials.append(QRegExp(QLatin1String("\\b")+s+QLatin1String("\\b"))); | 42 | specials.append(QRegExp(QLatin1String("\\b")+s+QLatin1String("\\b"))); | ||
43 | } | 43 | } | ||
44 | 44 | | |||
45 | void RHighlighter::refreshSyntaxRegExps() | | |||
46 | { | | |||
47 | emit syntaxRegExps(variables,functions); | | |||
48 | } | | |||
49 | | ||||
50 | // FIXME: due to lack of lookbehinds in QRegExp here we use a flag showing if we need to shift the boundary of formatting | 45 | // FIXME: due to lack of lookbehinds in QRegExp here we use a flag showing if we need to shift the boundary of formatting | ||
51 | // to make up for the accidentally matched character | 46 | // to make up for the accidentally matched character | ||
52 | void RHighlighter::formatRule(const QRegExp &p, const QTextCharFormat &fmt, const QString& text,bool shift) | 47 | void RHighlighter::formatRule(const QRegExp &p, const QTextCharFormat &fmt, const QString& text,bool shift) | ||
53 | { | 48 | { | ||
54 | int index = p.indexIn(text); | 49 | int index = p.indexIn(text); | ||
55 | while (index >= 0) { | 50 | while (index >= 0) { | ||
56 | int length = p.matchedLength(); | 51 | int length = p.matchedLength(); | ||
57 | setFormat(index+(shift?1:0), length-(shift?1:0), fmt); | 52 | setFormat(index+(shift?1:0), length-(shift?1:0), fmt); | ||
Show All 23 Lines | 65 | { | |||
81 | //formatRule(QRegExp("[^A-Za-z_]-?([0-9]+)?(((e|i)?-?)|\\.)[0-9]*L?"),numberFormat(),text,true); // TODO: erroneous number formats, refine | 76 | //formatRule(QRegExp("[^A-Za-z_]-?([0-9]+)?(((e|i)?-?)|\\.)[0-9]*L?"),numberFormat(),text,true); // TODO: erroneous number formats, refine | ||
82 | massFormat(operators,operatorFormat(),text); | 77 | massFormat(operators,operatorFormat(),text); | ||
83 | massFormat(specials,commentFormat(),text); // FIXME must be distinct | 78 | massFormat(specials,commentFormat(),text); // FIXME must be distinct | ||
84 | massFormat(functions,functionFormat(),text); | 79 | massFormat(functions,functionFormat(),text); | ||
85 | massFormat(variables,variableFormat(),text); | 80 | massFormat(variables,variableFormat(),text); | ||
86 | formatRule(QRegExp(QLatin1String("\"[^\"]+\"")),stringFormat(),text); // WARNING a bit redundant | 81 | formatRule(QRegExp(QLatin1String("\"[^\"]+\"")),stringFormat(),text); // WARNING a bit redundant | ||
87 | } | 82 | } | ||
88 | 83 | | |||
89 | void RHighlighter::updateHighlighting() | 84 | void RHighlighter::addUserDefinition(const QStringList& names, QVector<QRegExp>& vector) | ||
asemke: can the functions addUserDefinition(), removeUserDefinition(), addUserVariable()… | |||||
85 | { | ||||
86 | for (const QString s : names) | ||||
87 | if (!s.contains(QRegExp(QLatin1String("[^A-Za-z0-9_.]")))) | ||||
88 | vector.append(QRegExp(QLatin1String("\\b")+s+QLatin1String("\\b"))); | ||||
89 | | ||||
90 | emit rulesChanged(); | ||||
91 | } | ||||
92 | | ||||
93 | void RHighlighter::removeUserDefinition(const QStringList& names, QVector<QRegExp>& vector) | ||||
94 | { | ||||
95 | for (const QString var : names) | ||||
96 | for (int i = 0; i < vector.size(); i++) | ||||
97 | if (vector[i].pattern() == QLatin1String("\\b")+var+QLatin1String("\\b")) | ||||
90 | { | 98 | { | ||
99 | vector.remove(i); | ||||
100 | break; | ||||
101 | } | ||||
102 | | ||||
91 | emit rulesChanged(); | 103 | emit rulesChanged(); | ||
92 | } | 104 | } | ||
105 | | ||||
106 | void RHighlighter::addUserVariable(const QStringList& vars) | ||||
107 | { | ||||
108 | addUserDefinition(vars, variables); | ||||
109 | } | ||||
110 | | ||||
111 | void RHighlighter::removeUserVariable(const QStringList& vars) | ||||
112 | { | ||||
113 | removeUserDefinition(vars, variables); | ||||
114 | } | ||||
115 | | ||||
116 | void RHighlighter::removeUserFunction(const QStringList& funcs) | ||||
117 | { | ||||
118 | removeUserDefinition(funcs, functions); | ||||
119 | } | ||||
120 | | ||||
121 | void RHighlighter::addUserFunction(const QStringList& funcs) | ||||
122 | { | ||||
123 | addUserDefinition(funcs, functions); | ||||
124 | } |
can the functions addUserDefinition(), removeUserDefinition(), addUserVariable(), removeUserVariable(), addUserFunction() and removeUserFunction() be moved to the base class DefaultHighlighter?