Fix that raw string literals that close on same line were not terminated

With the built-in model, which affects basic highlighting.

Task-number: QTCREATORBUG-17720
Change-Id: I7369d7288d9c2c8e5ef36fc27549121014527e58
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Eike Ziller
2017-05-18 12:46:19 +02:00
parent a37c8add58
commit 4e35cc2ea8
2 changed files with 19 additions and 1 deletions

View File

@@ -748,6 +748,7 @@ void Lexer::scanRawStringLiteral(Token *tok, unsigned char hint)
int delimLength = -1; int delimLength = -1;
const char *closingDelimCandidate = 0; const char *closingDelimCandidate = 0;
bool closed = false;
while (_yychar) { while (_yychar) {
if (_yychar == '(' && delimLength == -1) { if (_yychar == '(' && delimLength == -1) {
delimLength = _currentChar - yytext; delimLength = _currentChar - yytext;
@@ -769,6 +770,7 @@ void Lexer::scanRawStringLiteral(Token *tok, unsigned char hint)
if (_yychar == '"') { if (_yychar == '"') {
if (delimLength == _currentChar - closingDelimCandidate) { if (delimLength == _currentChar - closingDelimCandidate) {
// Got a matching closing delimiter. // Got a matching closing delimiter.
closed = true;
break; break;
} }
} }
@@ -802,7 +804,7 @@ void Lexer::scanRawStringLiteral(Token *tok, unsigned char hint)
else else
tok->f.kind = T_RAW_STRING_LITERAL; tok->f.kind = T_RAW_STRING_LITERAL;
if (!_yychar) if (!closed)
s._tokenKind = tok->f.kind; s._tokenKind = tok->f.kind;
} }

View File

@@ -766,6 +766,22 @@ void tst_SimpleLexer::incremental_data()
<< _("bar\";") << _("bar\";")
<< (TokenKindList() << T_STRING_LITERAL << T_SEMICOLON); << (TokenKindList() << T_STRING_LITERAL << T_SEMICOLON);
QTest::newRow("multiline_raw_string_literal_1")
<< _("R\"delim(foo")
<< (TokenKindList() << T_RAW_STRING_LITERAL);
QTest::newRow("multiline_raw_string_literal_2")
<< _("bar)delim\"")
<< (TokenKindList() << T_RAW_STRING_LITERAL);
QTest::newRow("token_after_raw_string_literal_1")
<< _("R\"delim( )delim\"")
<< (TokenKindList() << T_RAW_STRING_LITERAL);
QTest::newRow("token_after_raw_string_literal_2")
<< _(";")
<< (TokenKindList() << T_SEMICOLON);
QTest::newRow("simple_cpp_comment") QTest::newRow("simple_cpp_comment")
<< _("//foo") << _("//foo")
<< (TokenKindList() << T_CPP_COMMENT); << (TokenKindList() << T_CPP_COMMENT);