New syntax highlighter not complete.

- Supports comments
- more efficient as it scans the text block instead of repeatedly searching throught the whole block
- type matching based on catalog (but need to add aliases manually)
- added many keywords

todo:
- heap corruption bug
- symbol stops at special char like parenthese or operator or something similar.
This commit is contained in:
Eelke Klein 2017-02-07 21:39:45 +01:00
parent 4364f427bf
commit 37e8882a3c
11 changed files with 311 additions and 72 deletions

34
SqlSyntaxHighlighter.h Normal file
View file

@ -0,0 +1,34 @@
#ifndef SQLSYNTAXHIGHLIGHTER_H
#define SQLSYNTAXHIGHLIGHTER_H
#include <QSyntaxHighlighter>
#include <QTextFormat>
#include <unordered_set>
#include "util.h"
using t_SymbolSet = std::unordered_set<QString>;
class PgTypeContainer;
class SqlSyntaxHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
SqlSyntaxHighlighter(QTextDocument *parent = nullptr);
~SqlSyntaxHighlighter();
void setTypes(const PgTypeContainer *types);
protected:
void highlightBlock(const QString &text) override;
private:
QTextCharFormat m_keywordFormat;
QTextCharFormat m_commentFormat;
QTextCharFormat m_quotedStringFormat;
QTextCharFormat m_typeFormat;
t_SymbolSet m_typeNames;
};
#endif // SQLSYNTAXHIGHLIGHTER_H