THe SqlLexer also now recognizes casts.

This commit is contained in:
eelke 2018-01-06 21:18:28 +01:00
parent a99f059b70
commit b436814eb5
3 changed files with 55 additions and 1 deletions

View file

@ -23,6 +23,24 @@ QChar SqlLexer::peekChar()
return result;
}
//+ - * / < > = ~ ! @ # % ^ & | ` ?
//There are a few restrictions on your choice of name:
// -- and /* cannot appear anywhere in an operator name, since they will be taken as the start of a comment.
// A multicharacter operator name cannot end in + or -, unless the name also contains at least one of these characters:
// ~ ! @ # % ^ & | ` ?
// For example, @- is an allowed operator name, but *- is not. This restriction allows PostgreSQL to parse SQL-compliant commands without requiring spaces between tokens.
// The use of => as an operator name is deprecated. It may be disallowed altogether in a future release.
//The operator != is mapped to <> on input, so these two names are always equivalent.
template <typename C>
inline bool isOperatorChar(C c)
{
return c == '+' || c == '-' || c == '*' || c == '/' || c == '<' || c == '>' || c == '='
|| c == '~' || c == '!' || c == '@' || c == '#' || c == '%' || c == '^' || c == '&'
|| c == '|' || c == '`' || c == '?';
}
/**
* @brief NextBasicToken
* @param in
@ -75,6 +93,17 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent
else if (c == '$') {
return parseDollarQuote(startpos, length, tokentype, out);
}
else if (c == ':') {
c = peekChar();
if (c == ':') {
nextChar();
length = m_pos - startpos;
tokentype = BasicTokenType::Cast;
QStringRef sr(&m_block, startpos, length);
out = sr.toString();
return true;
}
}
else {
// Undetermined symbol
for (;;) {