Changeset View
Changeset View
Standalone View
Standalone View
src/backends/R/rhighlighter.cpp
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | 16 | | |||
17 | --- | 17 | --- | ||
18 | Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com> | 18 | Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com> | ||
19 | Copyright (C) 2010 Oleksiy Protas <elfy.ua@gmail.com> | 19 | Copyright (C) 2010 Oleksiy Protas <elfy.ua@gmail.com> | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "rhighlighter.h" | 22 | #include "rhighlighter.h" | ||
23 | #include "rkeywords.h" | 23 | #include "rkeywords.h" | ||
24 | #include "rsession.h" | ||||
24 | 25 | | |||
25 | #include <QTextEdit> | 26 | #include <QTextEdit> | ||
26 | #include <QDebug> | 27 | #include <QDebug> | ||
27 | 28 | | |||
28 | const QStringList RHighlighter::operators_list=QStringList() | 29 | const QStringList RHighlighter::operators_list=QStringList() | ||
29 | << QLatin1String("(\\+|\\-|\*{1,2}|/|<=?|>=?|={1,2}|\\!=?|\|{1,2}|&{1,2}|:{1,3}|\^|@|\\$|~)") | 30 | << QLatin1String("(\\+|\\-|\*{1,2}|/|<=?|>=?|={1,2}|\\!=?|\|{1,2}|&{1,2}|:{1,3}|\^|@|\\$|~)") | ||
30 | << QLatin1String("%[^%]*%"); // Taken in r.xml syntax file from KSyntaxHighlighter | 31 | << QLatin1String("%[^%]*%"); // Taken in r.xml syntax file from KSyntaxHighlighter | ||
31 | 32 | | |||
32 | const QStringList RHighlighter::specials_list=QStringList() | 33 | const QStringList RHighlighter::specials_list=QStringList() | ||
33 | << QLatin1String("BUG") << QLatin1String("TODO") << QLatin1String("FIXME") << QLatin1String("NB") << QLatin1String("WARNING") << QLatin1String("ERROR"); | 34 | << QLatin1String("BUG") << QLatin1String("TODO") << QLatin1String("FIXME") << QLatin1String("NB") << QLatin1String("WARNING") << QLatin1String("ERROR"); | ||
34 | 35 | | |||
35 | RHighlighter::RHighlighter(QObject* parent) : Cantor::DefaultHighlighter(parent) | 36 | RHighlighter::RHighlighter(QObject* parent, RSession* session) : Cantor::DefaultHighlighter(parent, session) | ||
36 | { | 37 | { | ||
37 | addKeywords(RKeywords::instance()->keywords()); | 38 | addKeywords(RKeywords::instance()->keywords()); | ||
38 | 39 | | |||
39 | foreach (const QString& s, operators_list) | 40 | foreach (const QString& s, operators_list) | ||
40 | operators.append(QRegExp(s)); | 41 | operators.append(QRegExp(s)); | ||
41 | foreach (const QString& s, specials_list) | 42 | foreach (const QString& s, specials_list) | ||
42 | specials.append(QRegExp(QLatin1String("\\b")+s+QLatin1String("\\b"))); | 43 | specials.append(QRegExp(QLatin1String("\\b")+s+QLatin1String("\\b"))); | ||
43 | } | 44 | } | ||
44 | 45 | | |||
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 | 46 | // 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 | 47 | // to make up for the accidentally matched character | ||
52 | void RHighlighter::formatRule(const QRegExp &p, const QTextCharFormat &fmt, const QString& text,bool shift) | 48 | void RHighlighter::formatRule(const QRegExp &p, const QTextCharFormat &fmt, const QString& text,bool shift) | ||
53 | { | 49 | { | ||
54 | int index = p.indexIn(text); | 50 | int index = p.indexIn(text); | ||
55 | while (index >= 0) { | 51 | while (index >= 0) { | ||
56 | int length = p.matchedLength(); | 52 | int length = p.matchedLength(); | ||
57 | setFormat(index+(shift?1:0), length-(shift?1:0), fmt); | 53 | setFormat(index+(shift?1:0), length-(shift?1:0), fmt); | ||
Show All 21 Lines | 66 | { | |||
79 | formatRule(QRegExp(QLatin1String("\\b[A-Za-z0-9_]+(?=\\()")),errorFormat(),text); | 75 | formatRule(QRegExp(QLatin1String("\\b[A-Za-z0-9_]+(?=\\()")),errorFormat(),text); | ||
80 | 76 | | |||
81 | //formatRule(QRegExp("[^A-Za-z_]-?([0-9]+)?(((e|i)?-?)|\\.)[0-9]*L?"),numberFormat(),text,true); // TODO: erroneous number formats, refine | 77 | //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); | 78 | massFormat(operators,operatorFormat(),text); | ||
83 | massFormat(specials,commentFormat(),text); // FIXME must be distinct | 79 | massFormat(specials,commentFormat(),text); // FIXME must be distinct | ||
84 | massFormat(functions,functionFormat(),text); | 80 | massFormat(functions,functionFormat(),text); | ||
85 | massFormat(variables,variableFormat(),text); | 81 | massFormat(variables,variableFormat(),text); | ||
86 | formatRule(QRegExp(QLatin1String("\"[^\"]+\"")),stringFormat(),text); // WARNING a bit redundant | 82 | formatRule(QRegExp(QLatin1String("\"[^\"]+\"")),stringFormat(),text); // WARNING a bit redundant | ||
87 | } | 83 | } | ||
asemke: can the functions addUserDefinition(), removeUserDefinition(), addUserVariable()… | |||||
88 | | ||||
89 | void RHighlighter::updateHighlighting() | | |||
90 | { | | |||
91 | emit rulesChanged(); | | |||
92 | } | |
can the functions addUserDefinition(), removeUserDefinition(), addUserVariable(), removeUserVariable(), addUserFunction() and removeUserFunction() be moved to the base class DefaultHighlighter?