diff options
| author | 2021-12-17 07:06:30 -0500 | |
|---|---|---|
| committer | 2021-12-17 07:06:30 -0500 | |
| commit | 1fdc150116cad39aae5c5da407c3312b47a59e3a (patch) | |
| tree | 123c79a4d7ad2d45781ba03ce939f7539fb428d8 /SQLiteStudio3/guiSQLiteStudio/sqlitesyntaxhighlighter.cpp | |
| parent | feda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (diff) | |
New upstream version 3.3.3+dfsg1.upstream/3.3.3+dfsg1
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/sqlitesyntaxhighlighter.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/sqlitesyntaxhighlighter.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/sqlitesyntaxhighlighter.cpp b/SQLiteStudio3/guiSQLiteStudio/sqlitesyntaxhighlighter.cpp index 55ccc08..92679e2 100644 --- a/SQLiteStudio3/guiSQLiteStudio/sqlitesyntaxhighlighter.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/sqlitesyntaxhighlighter.cpp @@ -1,10 +1,13 @@ #include "sqlitesyntaxhighlighter.h" #include "parser/lexer.h" -#include "uiconfig.h" #include "services/config.h" +#include "style.h" +#include "parser/keywords.h" #include <QTextDocument> #include <QDebug> #include <QPlainTextEdit> +#include <QApplication> +#include <QStyle> SqliteSyntaxHighlighter::SqliteSyntaxHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent) @@ -15,12 +18,6 @@ SqliteSyntaxHighlighter::SqliteSyntaxHighlighter(QTextDocument *parent) : connect(CFG, SIGNAL(massSaveCommitted()), this, SLOT(setupFormats())); } -void SqliteSyntaxHighlighter::setSqliteVersion(int version) -{ - this->sqliteVersion = version; - rehighlight(); -} - void SqliteSyntaxHighlighter::setFormat(SqliteSyntaxHighlighter::State state, QTextCharFormat format) { formats[state] = format; @@ -36,46 +33,47 @@ void SqliteSyntaxHighlighter::setupFormats() QTextCharFormat format; // Standard - format.setForeground(CFG_UI.Colors.SqlEditorForeground.get()); + format.setForeground(QApplication::style()->standardPalette().text()); format.setFontWeight(QFont::Normal); format.setFontItalic(false); formats[State::STANDARD] = format; // Parenthesis + format.setForeground(QApplication::style()->standardPalette().text()); formats[State::PARENTHESIS] = format; // String - format.setForeground(CFG_UI.Colors.SqlEditorStringFg.get()); + format.setForeground(STYLE->extendedPalette().editorString()); format.setFontWeight(QFont::Normal); - format.setFontItalic(false); + format.setFontItalic(true); formats[State::STRING] = format; // Keyword - format.setForeground(CFG_UI.Colors.SqlEditorKeywordFg.get()); - format.setFontWeight(QFont::Bold); + format.setForeground(QApplication::style()->standardPalette().windowText()); + format.setFontWeight(QFont::ExtraBold); format.setFontItalic(false); formats[State::KEYWORD] = format; // BindParam - format.setForeground(CFG_UI.Colors.SqlEditorBindParamFg.get()); + format.setForeground(QApplication::style()->standardPalette().linkVisited()); format.setFontWeight(QFont::Normal); format.setFontItalic(false); formats[State::BIND_PARAM] = format; // Blob - format.setForeground(CFG_UI.Colors.SqlEditorBlobFg.get()); + format.setForeground(QApplication::style()->standardPalette().text()); format.setFontWeight(QFont::Normal); format.setFontItalic(false); formats[State::BLOB] = format; // Comment - format.setForeground(CFG_UI.Colors.SqlEditorCommentFg.get()); + format.setForeground(QApplication::style()->standardPalette().dark()); format.setFontWeight(QFont::Normal); format.setFontItalic(true); formats[State::COMMENT] = format; // Number - format.setForeground(CFG_UI.Colors.SqlEditorNumberFg.get()); + format.setForeground(QApplication::style()->standardPalette().text()); format.setFontWeight(QFont::Normal); format.setFontItalic(false); formats[State::NUMBER] = format; @@ -139,7 +137,7 @@ void SqliteSyntaxHighlighter::highlightBlock(const QString &text) idxModifier += statePrefix.size(); } - Lexer lexer(sqliteVersion == 2 ? Dialect::Sqlite2 : Dialect::Sqlite3); + Lexer lexer; lexer.setTolerantMode(true); lexer.prepare(statePrefix+text); @@ -157,22 +155,25 @@ void SqliteSyntaxHighlighter::highlightBlock(const QString &text) TextBlockData* data = new TextBlockData(); int errorStart = -1; TokenPtr token = lexer.getToken(); + TokenPtr aheadToken; while (token) { - if (handleToken(token, idxModifier, errorStart, data, prevData)) + aheadToken = lexer.getToken(); + + if (handleToken(token, aheadToken, idxModifier, errorStart, data, prevData)) errorStart = token->start + currentBlock().position(); if (data->getEndsWithQuerySeparator()) errorStart = -1; handleParenthesis(token, data); - token = lexer.getToken(); + token = aheadToken; } setCurrentBlockUserData(data); } -bool SqliteSyntaxHighlighter::handleToken(TokenPtr token, qint32 idxModifier, int errorStart, TextBlockData* currBlockData, +bool SqliteSyntaxHighlighter::handleToken(TokenPtr token, TokenPtr aheadToken, qint32 idxModifier, int errorStart, TextBlockData* currBlockData, TextBlockData* previousBlockData) { qint64 start = token->start - idxModifier; @@ -186,6 +187,9 @@ bool SqliteSyntaxHighlighter::handleToken(TokenPtr token, qint32 idxModifier, in if (createTriggerContext && token->type == Token::OTHER && (token->value.toLower() == "old" || token->value.toLower() == "new")) token->type = Token::KEYWORD; + if (aheadToken && aheadToken->type == Token::PAR_LEFT && token->type == Token::KEYWORD && isSoftKeyword(token->value)) + token->type = Token::OTHER; + bool limitedDamage = false; bool querySeparator = (token->type == Token::Type::OPERATOR && token->value == ";"); bool error = isError(start, lgt, &limitedDamage); @@ -203,7 +207,7 @@ bool SqliteSyntaxHighlighter::handleToken(TokenPtr token, qint32 idxModifier, in ); bool fatalError = (error && !limitedDamage) || wasError; - QTextCharFormat format; + QTextCharFormat format = formats[State::STANDARD]; // Applying valid object format. applyValidObjectFormat(format, valid, error, wasError); @@ -245,7 +249,7 @@ void SqliteSyntaxHighlighter::applyValidObjectFormat(QTextCharFormat& format, bo if (isError || wasError || !isValid) return; - format.setForeground(CFG_UI.Colors.SqlEditorValidObject.get()); + format.setForeground(QApplication::style()->standardPalette().link()); if (objectLinksEnabled) format.setUnderlineStyle(QTextCharFormat::SingleUnderline); } |
