aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/cplusplus/Lexer.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-09-21 11:46:47 +0200
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-09-23 07:22:13 +0000
commitd46e5025e5ff43fc76b875165479d03de558bd81 (patch)
tree4995a789a625595b6383123c0ba1dede4e05c0ae /src/libs/3rdparty/cplusplus/Lexer.cpp
parent3edd1e575e75b3e29e37cf17ea2ac938d8cd2c3e (diff)
C++: Highlight multi-line raw string literals
Task-number: QTCREATORBUG-13094 Change-Id: I4e6b8c202677f4c1cd4df95d59130ba8379e72fe Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/libs/3rdparty/cplusplus/Lexer.cpp')
-rw-r--r--src/libs/3rdparty/cplusplus/Lexer.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp
index 4c76e96f08..ecf7895df6 100644
--- a/src/libs/3rdparty/cplusplus/Lexer.cpp
+++ b/src/libs/3rdparty/cplusplus/Lexer.cpp
@@ -135,11 +135,18 @@ void Lexer::scan(Token *tok)
tok->f.utf16chars = _currentCharUtf16 - _tokenStartUtf16;
}
+static bool isRawStringLiteral(unsigned char kind)
+{
+ return kind >= T_FIRST_RAW_STRING_LITERAL
+ && kind <= T_LAST_RAW_STRING_LITERAL;
+}
+
static bool isMultiLineToken(unsigned char kind)
{
return kind == T_EOF_SYMBOL
|| kind == T_COMMENT
- || kind == T_DOXY_COMMENT;
+ || kind == T_DOXY_COMMENT
+ || isRawStringLiteral(kind);
}
void Lexer::scan_helper(Token *tok)
@@ -207,7 +214,12 @@ void Lexer::scan_helper(Token *tok)
_state = 0;
scanCppComment(originalKind);
return;
- } else { // strings
+ } else if (isRawStringLiteral(s._tokenKind)) {
+ tok->f.kind = s._tokenKind;
+ if (scanUntilRawStringLiteralEndSimple())
+ _state = 0;
+ return;
+ } else { // non-raw strings
tok->f.joined = true;
tok->f.kind = s._tokenKind;
_state = 0;
@@ -740,6 +752,32 @@ void Lexer::scanRawStringLiteral(Token *tok, unsigned char hint)
tok->f.kind = T_RAW_UTF8_STRING_LITERAL;
else
tok->f.kind = T_RAW_STRING_LITERAL;
+
+ if (!_yychar)
+ s._tokenKind = tok->f.kind;
+}
+
+// In the highlighting case we don't have any further information
+// like the delimiter or its length, so just match for: ...)..."
+bool Lexer::scanUntilRawStringLiteralEndSimple()
+{
+ bool closingParenthesisPassed = false;
+
+ while (_yychar) {
+ if (_yychar == ')') {
+ yyinp();
+ closingParenthesisPassed = true;
+ } else {
+ if (closingParenthesisPassed && _yychar == '"') {
+ yyinp();
+ return true;
+ } else {
+ yyinp();
+ }
+ }
+ }
+
+ return false;
}
void Lexer::scanCharLiteral(Token *tok, unsigned char hint)