Debugger: Fix tokenizer bug.

- When detecting a possible start of string literal, ensure that a
  terminator was actually found, otherwise simply consider it as a
  single character token. Otherwise, cases such as an apostrophe in
  a C-style comment that spanned a single line would result in us
  missing the token for the comment close, and highlighting all
  subsequent lines until such a token was encountered as comments.
This commit is contained in:
Rene Gollent
2014-12-28 23:43:56 -05:00
parent 9c3e96bfb7
commit 15852b070a
2 changed files with 15 additions and 2 deletions
@@ -172,17 +172,27 @@ Tokenizer::NextToken()
fCurrentToken = Token(begin, length, _CurrentPos() - length, fCurrentToken = Token(begin, length, _CurrentPos() - length,
TOKEN_IDENTIFIER); TOKEN_IDENTIFIER);
} else if (*fCurrentChar == '"' || *fCurrentChar == '\'') { } else if (*fCurrentChar == '"' || *fCurrentChar == '\'') {
bool terminatorFound = false;
const char* begin = fCurrentChar++; const char* begin = fCurrentChar++;
while (*fCurrentChar != 0) { while (*fCurrentChar != 0) {
if (*fCurrentChar == '\\') { if (*fCurrentChar == '\\') {
if (*(fCurrentChar++) != 0) if (*(fCurrentChar++) != 0)
fCurrentChar++; fCurrentChar++;
} else if (*(fCurrentChar++) == *begin) } else if (*(fCurrentChar++) == *begin) {
terminatorFound = true;
break; break;
}
} }
int32 tokenType = TOKEN_STRING_LITERAL;
if (!terminatorFound) {
tokenType = *begin == '"' ? TOKEN_DOUBLE_QUOTE
: TOKEN_SINGLE_QUOTE;
fCurrentChar = begin + 1;
}
int32 length = fCurrentChar - begin; int32 length = fCurrentChar - begin;
fCurrentToken = Token(begin, length, _CurrentPos() - length, fCurrentToken = Token(begin, length, _CurrentPos() - length,
TOKEN_STRING_LITERAL); tokenType);
} else { } else {
if (!_ParseOperator()) { if (!_ParseOperator()) {
int32 type = TOKEN_NONE; int32 type = TOKEN_NONE;
@@ -65,6 +65,9 @@ enum {
TOKEN_PERIOD, TOKEN_PERIOD,
TOKEN_POUND, TOKEN_POUND,
TOKEN_SINGLE_QUOTE,
TOKEN_DOUBLE_QUOTE,
TOKEN_STRING_LITERAL, TOKEN_STRING_LITERAL,
TOKEN_BEGIN_COMMENT_BLOCK, TOKEN_BEGIN_COMMENT_BLOCK,
TOKEN_END_COMMENT_BLOCK, TOKEN_END_COMMENT_BLOCK,