CppEditor: Fix highlighting of raw string literals

... with the built-in highlighter.
Pass the necessary context information in and out of the SimpleLexer.

Task-number: QTCREATORBUG-26211
Fixes: QTCREATORBUG-26425
Fixes: QTCREATORBUG-26615
Change-Id: Id72f743e07ae117ca51b0d5e527b208dda133b7e
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-12-08 13:57:24 +01:00
parent 3eef024960
commit a3af941adf
7 changed files with 79 additions and 22 deletions

View File

@@ -67,6 +67,7 @@ Tokens SimpleLexer::operator()(const QString &text, int state)
const char *lastChar = firstChar + bytes.size();
Lexer lex(firstChar, lastChar);
lex.setExpectedRawStringSuffix(_expectedRawStringSuffix);
lex.setLanguageFeatures(_languageFeatures);
lex.setStartWithNewline(true);
lex.setPreprocessorMode(_ppMode);
@@ -108,6 +109,7 @@ Tokens SimpleLexer::operator()(const QString &text, int state)
}
_lastState = lex.state();
_expectedRawStringSuffix = lex.expectedRawStringSuffix();
return tokens;
}

View File

@@ -59,6 +59,10 @@ public:
int state() const
{ return _lastState; }
QByteArray expectedRawStringSuffix() const { return _expectedRawStringSuffix; }
void setExpectedRawStringSuffix(const QByteArray &suffix)
{ _expectedRawStringSuffix = suffix; }
static int tokenAt(const Tokens &tokens, int utf16charsOffset);
static Token tokenAt(const QString &text,
int utf16charsOffset,
@@ -68,6 +72,7 @@ public:
static int tokenBefore(const Tokens &tokens, int utf16charsOffset);
private:
QByteArray _expectedRawStringSuffix;
int _lastState;
LanguageFeatures _languageFeatures;
bool _skipComments: 1;