Big cleanup
This commit is contained in:
parent
d3080a08bb
commit
8b671090a0
55 changed files with 214 additions and 3967 deletions
|
|
@ -79,147 +79,119 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent
|
|||
while (true) {
|
||||
startpos = m_pos;
|
||||
QChar c = nextChar();
|
||||
// if (LexerState::Null == m_state) {
|
||||
if (c == '\n') {
|
||||
if (m_returnWhitespace) {
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::NewLine;
|
||||
out = "\n";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (c.isSpace()) {
|
||||
// Just skip whitespace
|
||||
if (m_returnWhitespace) {
|
||||
for (;;) {
|
||||
c = peekChar();
|
||||
if (c != QChar::Null && c.isSpace() && c != '\n')
|
||||
nextChar();
|
||||
else
|
||||
break;
|
||||
}
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::WhiteSpace;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (c == '-' && peekChar() == '-') { // two dashes, start of comment
|
||||
// Loop till end of line or end of block
|
||||
c = nextChar();
|
||||
for (;;) {
|
||||
c = peekChar();
|
||||
if (c != QChar::Null && c != '\n')
|
||||
nextChar();
|
||||
else
|
||||
break;
|
||||
}
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::Comment;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
else if (c == ':') {
|
||||
c = peekChar();
|
||||
if (c == ':') {
|
||||
nextChar();
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::Cast;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (isSelf(c)) {
|
||||
length = m_pos - startpos;
|
||||
if (c == ',')
|
||||
tokentype = BasicTokenType::Comma;
|
||||
else
|
||||
tokentype = BasicTokenType::Self;
|
||||
|
||||
out = m_block.mid(startpos, length);
|
||||
if (c == '\n') {
|
||||
if (m_returnWhitespace) {
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::NewLine;
|
||||
out = "\n";
|
||||
return true;
|
||||
}
|
||||
else if (isOperatorChar(c)) {
|
||||
while (true) {
|
||||
QChar c = peekChar();
|
||||
if (isOperatorChar(c)) {
|
||||
nextChar();
|
||||
}
|
||||
else {
|
||||
// unexpected end, pretend nothings wrong
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::Operator;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (c == '\'') {
|
||||
// Single quoted string so it's an SQL text literal
|
||||
if (parseSingleQuotedString(startpos, length, tokentype)) {
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (c == '"') {
|
||||
// Double quoted identifier
|
||||
if (parseDoubleQuotedIdentifier(startpos, length, tokentype)) {
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// else if (c == '/' && peekChar() == '*') {
|
||||
// nextChar();
|
||||
// m_state = LexerState::InBlockComment;
|
||||
// }
|
||||
else if (c == QChar::Null) {
|
||||
length = 0;
|
||||
tokentype = BasicTokenType::End;
|
||||
return true;
|
||||
}
|
||||
else if (c == '$') {
|
||||
return parseDollarQuote(startpos, length, tokentype, out);
|
||||
}
|
||||
else {
|
||||
// Undetermined symbol
|
||||
for (;;) {
|
||||
c = peekChar();
|
||||
if (c.isLetterOrNumber() || c == '_')
|
||||
nextChar();
|
||||
else
|
||||
break;
|
||||
}
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::Symbol;
|
||||
}
|
||||
else if (c.isSpace()) {
|
||||
// Just skip whitespace
|
||||
if (m_returnWhitespace) {
|
||||
for (;;) {
|
||||
c = peekChar();
|
||||
if (c != QChar::Null && c.isSpace() && c != '\n')
|
||||
nextChar();
|
||||
else
|
||||
break;
|
||||
}
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::WhiteSpace;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
// }
|
||||
// else if (LexerState::InBlockComment == m_state) {
|
||||
// if (c == QChar::Null) {
|
||||
// // eof current buffer, we need to return state so
|
||||
// if (m_pos == startpos) {
|
||||
// break;
|
||||
// }
|
||||
// else {
|
||||
// length = m_pos - startpos;
|
||||
// tokentype = BasicTokenType::OpenBlockComment;
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// else if (c == '*') {
|
||||
// nextChar();
|
||||
// if (peekChar() == '/') {
|
||||
// nextChar();
|
||||
// length = m_pos - startpos;
|
||||
// tokentype = BasicTokenType::BlockComment;
|
||||
// m_state = LexerState::Null;
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
else if (c == '-' && peekChar() == '-') { // two dashes, start of comment
|
||||
// Loop till end of line or end of block
|
||||
c = nextChar();
|
||||
for (;;) {
|
||||
c = peekChar();
|
||||
if (c != QChar::Null && c != '\n')
|
||||
nextChar();
|
||||
else
|
||||
break;
|
||||
}
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::Comment;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
else if (c == ':') {
|
||||
c = peekChar();
|
||||
if (c == ':') {
|
||||
nextChar();
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::Cast;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (isSelf(c)) {
|
||||
length = m_pos - startpos;
|
||||
if (c == ',')
|
||||
tokentype = BasicTokenType::Comma;
|
||||
else
|
||||
tokentype = BasicTokenType::Self;
|
||||
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
else if (isOperatorChar(c)) {
|
||||
while (true) {
|
||||
QChar c = peekChar();
|
||||
if (isOperatorChar(c)) {
|
||||
nextChar();
|
||||
}
|
||||
else {
|
||||
// unexpected end, pretend nothings wrong
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::Operator;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (c == '\'') {
|
||||
// Single quoted string so it's an SQL text literal
|
||||
if (parseSingleQuotedString(startpos, length, tokentype)) {
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (c == '"') {
|
||||
// Double quoted identifier
|
||||
if (parseDoubleQuotedIdentifier(startpos, length, tokentype)) {
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (c == QChar::Null) {
|
||||
length = 0;
|
||||
tokentype = BasicTokenType::End;
|
||||
return true;
|
||||
}
|
||||
else if (c == '$') {
|
||||
return parseDollarQuote(startpos, length, tokentype, out);
|
||||
}
|
||||
else {
|
||||
// Undetermined symbol
|
||||
for (;;) {
|
||||
c = peekChar();
|
||||
if (c.isLetterOrNumber() || c == '_')
|
||||
nextChar();
|
||||
else
|
||||
break;
|
||||
}
|
||||
length = m_pos - startpos;
|
||||
tokentype = BasicTokenType::Symbol;
|
||||
out = m_block.mid(startpos, length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -298,11 +270,9 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token
|
|||
}
|
||||
|
||||
if (c.isLetter()) {
|
||||
// is this a dollar quote?
|
||||
while (true) {
|
||||
c = nextChar();
|
||||
if (c == '$') {
|
||||
// Found valid dollar quote
|
||||
tokentype = BasicTokenType::DollarQuote;
|
||||
length = m_pos - startpos;
|
||||
out = m_block.mid(startpos, length);
|
||||
|
|
@ -310,7 +280,6 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token
|
|||
}
|
||||
|
||||
if (!c.isLetter()) {
|
||||
// ERROR, unallowed character
|
||||
tokentype = BasicTokenType::None;
|
||||
length = m_pos - startpos;
|
||||
out = m_block.mid(startpos, length);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue