2017-02-11 08:03:10 +01:00
|
|
|
|
#ifndef SQLLEXER_H
|
|
|
|
|
|
#define SQLLEXER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
|
|
|
|
enum class BasicTokenType {
|
|
|
|
|
|
None,
|
|
|
|
|
|
End, // End of input
|
|
|
|
|
|
Symbol, // can be many things, keyword, object name, operator, ..
|
|
|
|
|
|
Comment,
|
2017-02-26 19:29:50 +01:00
|
|
|
|
BlockComment,
|
|
|
|
|
|
OpenBlockComment, // Busy with a block comment end not detected before end of current input
|
2017-02-11 08:03:10 +01:00
|
|
|
|
QuotedString,
|
2017-09-10 10:13:58 +02:00
|
|
|
|
DollarQuote, // Return the dollar quote tag, do not consume the entire string (potentially long)
|
|
|
|
|
|
QuotedIdentifier,
|
|
|
|
|
|
Parameter
|
2017-02-11 08:03:10 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum class LexerState {
|
|
|
|
|
|
Null,
|
2017-02-26 19:29:50 +01:00
|
|
|
|
InDollarQuotedString,
|
|
|
|
|
|
InBlockComment
|
2017-02-11 08:03:10 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SqlLexer {
|
|
|
|
|
|
public:
|
|
|
|
|
|
SqlLexer(const QString &block, LexerState currentstate);
|
|
|
|
|
|
QChar nextChar();
|
|
|
|
|
|
QChar peekChar();
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @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(int &startpos, int &length, BasicTokenType &tokentype, QString &out);
|
|
|
|
|
|
|
2017-02-26 19:29:50 +01:00
|
|
|
|
LexerState currentState() const { return m_state; }
|
2017-02-11 08:03:10 +01:00
|
|
|
|
private:
|
|
|
|
|
|
QString m_block;
|
|
|
|
|
|
int m_pos = 0;
|
|
|
|
|
|
LexerState m_state;
|
2017-02-12 08:13:38 +01:00
|
|
|
|
|
2017-02-26 19:29:50 +01:00
|
|
|
|
|
2017-02-11 08:03:10 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SQLLEXER_H
|