Het maken van de DB connectie gebeurd nu asynchroon.

This commit is contained in:
Eelke Klein 2016-12-27 15:41:11 +01:00
parent 27abce5a11
commit 3a8cc3d7f0
5 changed files with 207 additions and 18 deletions

View file

@ -1,14 +1,21 @@
#include "SqlHighlighter.h"
static const wchar_t *keywords[] = {
L"as", L"alter", L"all", L"and", L"any", L"by", L"column", L"create", L"database", L"from", L"full", L"group", L"having",
L"in", L"inner", L"join", L"left", L"not", L"or", L"order", L"outer", L"right", L"select", L"table", L"where"
L"as", L"alter", L"all", L"and", L"any", L"by", L"char", L"column", L"create", L"database", L"date", L"from", L"full", L"group", L"having",
L"in", L"inner", L"int", L"join", L"left", L"not", L"numeric", L"or", L"order", L"outer", L"right", L"select", L"smallint", L"table", L"time",
L"timestamp", L"timestamptz", L"varchar", L"where"
};
static const wchar_t *operators[] = {
L"+", L"-", L"*", L"/", L"<", L">", L"<=", L">=", L"<>", L"!=", L"~"
};
//static auto types = R"-(bigint|boolean|char|character varying|date|int[248]|integer|numeric|smallint|time|timestamp(?:tz)?|timestamp(?:\s+with\s+timezone)?|varchar)-";
//static auto err = R"-(left|right|inner|outer)-";
static_assert(sizeof(keywords)/4 == 25,
"sizeof keywords");
// static_assert(sizeof(keywords)/4 == 25,
// "sizeof keywords");
SqlHighlighter::SqlHighlighter(QTextDocument *parent)
@ -37,10 +44,61 @@ SqlHighlighter::SqlHighlighter(QTextDocument *parent)
// }
}
void NextBasicToken(const QString &in, int ofs, int &start, int &length)
{
// Basically parses for white space and chops based on white space
// it does also recognize comments and quoted strings/identifiers
namespace {
// Advances ofs to first whitespace or end of string, returns false at end of string
void skipWhiteSpace(const QString &in, int &ofs)
{
const int l = in.length();
while (ofs < l && in.at(ofs).isSpace()) ++ofs;
}
enum class BasicTokenType {
None,
End, // End of input
Symbol, // can be many things, keyword, object name, operator, ..
Comment,
QuotedString,
DollarQuotedString,
QuotedIdentifier
};
/**
* @brief NextBasicToken
* @param in
* @param ofs
* @param start
* @param length
* @return false when input seems invalid, it will return what it did recognize but something wasn't right, parser should try to recover
*/
bool NextBasicToken(const QString &in, int ofs, int &start, int &length, BasicTokenType &tokentype)
{
// Basically chops based on white space
// it does also recognize comments and quoted strings/identifiers
bool result = false;
skipWhiteSpace(in, ofs);
const int len = in.length();
while (ofs < len) {
if (ofs+1 < len && in.at(ofs) == L'-' && in.at(ofs+1) == L'-') {
// Start of comment, end of line is end of comment
}
else if (in.at(ofs) == L'\'') {
// Start of quoted string
}
else if (in.at(ofs) == L'"') {
// Start of quoted identifier
}
else if (in.at(ofs) == L'/' && ofs+1 < len && in.at(ofs+1) == L'*') {
// Start of C style comment, scan for end
}
}
return result;
}
}