Highlighter verbeterd en uitgebreid.

This commit is contained in:
Eelke Klein 2017-01-16 19:53:25 +01:00
parent fa9787adfd
commit 2b012b70eb

View file

@ -22,8 +22,14 @@ SqlHighlighter::SqlHighlighter(QTextDocument *parent)
: QSyntaxHighlighter(parent) : QSyntaxHighlighter(parent)
{ {
// { // {
static auto keywords = R"-(as|alter|all|and|any|by|column|create|database|delete|from|group|having|in|not|or|order|select|set|table|update|where|(?:(?:inner|(?:left|right|full)(\s+outer)?)\s+)?join)-"; static auto keywords =
// static auto types = R"-(bigint|boolean|char|character varying|date|int[248]|integer|numeric|smallint|time|timestamp(?:tz)?|timestamp(?:\s+with\s+timezone)?|varchar)-"; R"-(\balter\b|\ball\b|\band\b|\bany\b|\bas\b|\bby\b|\bcascade\b|\bcheck\b|\bcolumn\b|\bcopy\b|\bcreate\b|\bdatabase\b|\bdefault\b|\bdelete\b)-"
R"-(|\foreign\b|\bfrom\b|\bgroup\b|\bhaving\b|\bin\b|\bindex\b|\bis\b|\bkey\b|\blimit\b|\bnatural\b|\bnot\b|\bnull\b|\boffset\b|\bon\b)-"
R"-(|\bor\b|\border\b|\bover\b|\bparition\b|\bprimary\b|\breferences\b|\brestrict\b|\bselect\b|\btable\b|\btruncate\b|\bunique\b|\bupdate\b|\busing\b)-"
R"-(|\bwhere\b|\bwith\b|(?:(?:inner|(?:left|right|full)(\s+outer)?)\s+)?join)-";
static auto types =
R"-(\bbigint\b|\bboolean\b|\bchar\b|\bcharacter varying\b|\bdate\b|\bint[248]\b|\binteger\b|\bnumeric\b|\bsmallint\b)-"
R"-(|\btime\b|\btimestamp(?:tz)?\b|\btimestamp(?:\s+with\s+time\s+zone)?\b|\bvarchar\b)-";
// static auto err = R"-(left|right|inner|outer)-"; // static auto err = R"-(left|right|inner|outer)-";
// QTextCharFormat errFormat; // QTextCharFormat errFormat;
@ -32,14 +38,14 @@ SqlHighlighter::SqlHighlighter(QTextDocument *parent)
// highlightingRules.emplace_back(QRegExp(err, Qt::CaseInsensitive), errFormat); // highlightingRules.emplace_back(QRegExp(err, Qt::CaseInsensitive), errFormat);
QTextCharFormat keywordFormat; QTextCharFormat keywordFormat;
keywordFormat.setForeground(QColor(128, 128, 255)); keywordFormat.setForeground(QColor(64, 64, 192));
keywordFormat.setFontWeight(QFont::Bold); keywordFormat.setFontWeight(QFont::Bold);
highlightingRules.emplace_back(QRegExp(keywords, Qt::CaseInsensitive), keywordFormat); highlightingRules.emplace_back(QRegExp(keywords, Qt::CaseInsensitive), keywordFormat);
// QTextCharFormat typesFormat; QTextCharFormat typesFormat;
// typesFormat.setForeground(QColor(128, 255, 128)); typesFormat.setForeground(QColor(64, 192, 64));
// typesFormat.setFontWeight(QFont::Bold); typesFormat.setFontWeight(QFont::Bold);
// highlightingRules.emplace_back(QRegExp(types, Qt::CaseInsensitive), typesFormat); highlightingRules.emplace_back(QRegExp(types, Qt::CaseInsensitive), typesFormat);
// } // }
} }