forked from qt-creator/qt-creator
Revert "Editor: Highlight background for whitespaces in strings and comments"
The change brokes the Lexer.
This reverts commit e46a5579d3.
Change-Id: I3363c6eff74b53a7f2d9f417941cde07aaa92619
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
committed by
Leandro Melo
parent
b4eec17317
commit
6d85b53f9c
12
src/libs/3rdparty/cplusplus/Lexer.cpp
vendored
12
src/libs/3rdparty/cplusplus/Lexer.cpp
vendored
@@ -157,15 +157,10 @@ void Lexer::scan(Token *tok)
|
|||||||
void Lexer::scan_helper(Token *tok)
|
void Lexer::scan_helper(Token *tok)
|
||||||
{
|
{
|
||||||
_Lagain:
|
_Lagain:
|
||||||
_tokenStart = _currentChar;
|
|
||||||
tok->offset = _currentChar - _firstChar;
|
|
||||||
|
|
||||||
while (_yychar && std::isspace(_yychar)) {
|
while (_yychar && std::isspace(_yychar)) {
|
||||||
if (_yychar == '\n') {
|
if (_yychar == '\n') {
|
||||||
tok->f.joined = false;
|
tok->f.joined = false;
|
||||||
tok->f.newline = true;
|
tok->f.newline = true;
|
||||||
if (_state == State_MultiLineComment || _state == State_MultiLineDoxyComment)
|
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
tok->f.whitespace = true;
|
tok->f.whitespace = true;
|
||||||
}
|
}
|
||||||
@@ -175,10 +170,12 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
if (! _translationUnit)
|
if (! _translationUnit)
|
||||||
tok->lineno = _currentLine;
|
tok->lineno = _currentLine;
|
||||||
|
|
||||||
|
_tokenStart = _currentChar;
|
||||||
|
tok->offset = _currentChar - _firstChar;
|
||||||
|
|
||||||
if (_state == State_MultiLineComment || _state == State_MultiLineDoxyComment) {
|
if (_state == State_MultiLineComment || _state == State_MultiLineDoxyComment) {
|
||||||
const int originalState = _state;
|
const int originalState = _state;
|
||||||
|
|
||||||
|
|
||||||
if (! _yychar) {
|
if (! _yychar) {
|
||||||
tok->f.kind = T_EOF_SYMBOL;
|
tok->f.kind = T_EOF_SYMBOL;
|
||||||
return;
|
return;
|
||||||
@@ -207,9 +204,6 @@ void Lexer::scan_helper(Token *tok)
|
|||||||
return; // done
|
return; // done
|
||||||
}
|
}
|
||||||
|
|
||||||
_tokenStart = _currentChar;
|
|
||||||
tok->offset = _currentChar - _firstChar;
|
|
||||||
|
|
||||||
if (! _yychar) {
|
if (! _yychar) {
|
||||||
tok->f.kind = T_EOF_SYMBOL;
|
tok->f.kind = T_EOF_SYMBOL;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -162,15 +162,15 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
|
|
||||||
else if (tk.is(T_STRING_LITERAL) || tk.is(T_CHAR_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL) ||
|
else if (tk.is(T_STRING_LITERAL) || tk.is(T_CHAR_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL) ||
|
||||||
tk.is(T_AT_STRING_LITERAL))
|
tk.is(T_AT_STRING_LITERAL))
|
||||||
setFormat(tk.begin(), tk.length(), m_formats[CppStringFormat]);
|
highlightLine(text, tk.begin(), tk.length(), m_formats[CppStringFormat]);
|
||||||
|
|
||||||
else if (tk.is(T_WIDE_STRING_LITERAL) || tk.is(T_WIDE_CHAR_LITERAL))
|
else if (tk.is(T_WIDE_STRING_LITERAL) || tk.is(T_WIDE_CHAR_LITERAL))
|
||||||
setFormat(tk.begin(), tk.length(), m_formats[CppStringFormat]);
|
highlightLine(text, tk.begin(), tk.length(), m_formats[CppStringFormat]);
|
||||||
|
|
||||||
else if (tk.isComment()) {
|
else if (tk.isComment()) {
|
||||||
|
|
||||||
if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT))
|
if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT))
|
||||||
setFormat(tk.begin(), tk.length(), m_formats[CppCommentFormat]);
|
highlightLine(text, tk.begin(), tk.length(), m_formats[CppCommentFormat]);
|
||||||
|
|
||||||
else // a doxygen comment
|
else // a doxygen comment
|
||||||
highlightDoxygenComment(text, tk.begin(), tk.length());
|
highlightDoxygenComment(text, tk.begin(), tk.length());
|
||||||
@@ -212,7 +212,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
const Token tk = tokens.last();
|
const Token tk = tokens.last();
|
||||||
const int lastTokenEnd = tk.begin() + tk.length();
|
const int lastTokenEnd = tk.begin() + tk.length();
|
||||||
if (text.length() > lastTokenEnd)
|
if (text.length() > lastTokenEnd)
|
||||||
setFormat(lastTokenEnd, text.length() - lastTokenEnd, QTextCharFormat());
|
highlightLine(text, lastTokenEnd, text.length() - lastTokenEnd, QTextCharFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! initialState && state && ! tokens.isEmpty()) {
|
if (! initialState && state && ! tokens.isEmpty()) {
|
||||||
@@ -439,7 +439,7 @@ void CppHighlighter::highlightDoxygenComment(const QString &text, int position,
|
|||||||
|
|
||||||
int k = CppTools::classifyDoxygenTag(start, it - start);
|
int k = CppTools::classifyDoxygenTag(start, it - start);
|
||||||
if (k != CppTools::T_DOXY_IDENTIFIER) {
|
if (k != CppTools::T_DOXY_IDENTIFIER) {
|
||||||
setFormat(initial, start - uc - initial, format);
|
highlightLine(text, initial, start - uc - initial, format);
|
||||||
setFormat(start - uc - 1, it - start + 1, kwFormat);
|
setFormat(start - uc - 1, it - start + 1, kwFormat);
|
||||||
initial = it - uc;
|
initial = it - uc;
|
||||||
}
|
}
|
||||||
@@ -447,6 +447,6 @@ void CppHighlighter::highlightDoxygenComment(const QString &text, int position,
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
setFormat(initial, it - uc - initial, format);
|
highlightLine(text, initial, it - uc - initial, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,6 @@
|
|||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <SimpleLexer.h>
|
|
||||||
#include <Token.h>
|
|
||||||
|
|
||||||
#include <findcdbbreakpoint.h>
|
#include <findcdbbreakpoint.h>
|
||||||
|
|
||||||
@@ -52,14 +50,6 @@ private slots:
|
|||||||
|
|
||||||
void findBreakpoints();
|
void findBreakpoints();
|
||||||
void findBreakpoints2();
|
void findBreakpoints2();
|
||||||
|
|
||||||
void testLexerComment();
|
|
||||||
void testLexerComment2();
|
|
||||||
void testLexerComment3();
|
|
||||||
void testLexerMultiLineComment();
|
|
||||||
void testLexerMultiLineComment2();
|
|
||||||
void testLexerMultiLineComment3();
|
|
||||||
void testLexerMultiLineComment4();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_Misc::diagnosticClient_error()
|
void tst_Misc::diagnosticClient_error()
|
||||||
@@ -187,107 +177,5 @@ void tst_Misc::findBreakpoints2()
|
|||||||
QCOMPARE(findBreakpoint(7), 7U);
|
QCOMPARE(findBreakpoint(7), 7U);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Misc::testLexerComment() {
|
|
||||||
const QByteArray src("// int a = 42 ");
|
|
||||||
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setQtMocRunEnabled(false);
|
|
||||||
tokenize.setObjCEnabled(false);
|
|
||||||
tokenize.setCxx0xEnabled(true);
|
|
||||||
const QList<Token> tokens = tokenize(src);
|
|
||||||
|
|
||||||
QCOMPARE(tokenize.state(), 0);
|
|
||||||
QCOMPARE(tokens.size(), 1);
|
|
||||||
QCOMPARE(tokens[0].f.kind, 2U);
|
|
||||||
QCOMPARE(tokens[0].f.length, 17U);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Misc::testLexerComment2() {
|
|
||||||
const QByteArray src(" // int a = 42 ");
|
|
||||||
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setQtMocRunEnabled(false);
|
|
||||||
tokenize.setObjCEnabled(false);
|
|
||||||
tokenize.setCxx0xEnabled(true);
|
|
||||||
const QList<Token> tokens = tokenize(src);
|
|
||||||
|
|
||||||
QCOMPARE(tokenize.state(), 0);
|
|
||||||
QCOMPARE(tokens.size(), 1);
|
|
||||||
QCOMPARE(tokens[0].f.kind, 2U);
|
|
||||||
QCOMPARE(tokens[0].f.length, 17U);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Misc::testLexerComment3() {
|
|
||||||
const QByteArray src(" int main( int argc, char** argv) { // Foo m_foo = 42 /n");
|
|
||||||
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setQtMocRunEnabled(false);
|
|
||||||
tokenize.setObjCEnabled(false);
|
|
||||||
tokenize.setCxx0xEnabled(true);
|
|
||||||
const QList<Token> tokens = tokenize(src);
|
|
||||||
|
|
||||||
QCOMPARE(tokenize.state(), 0);
|
|
||||||
QCOMPARE(tokens.size(), 13);
|
|
||||||
QCOMPARE(tokens.last().f.kind, 2U);
|
|
||||||
QCOMPARE(tokens.last().f.length, 21U);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Misc::testLexerMultiLineComment() {
|
|
||||||
const QByteArray src("/* multi /n"
|
|
||||||
" * line /n");
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setQtMocRunEnabled(false);
|
|
||||||
tokenize.setObjCEnabled(false);
|
|
||||||
tokenize.setCxx0xEnabled(true);
|
|
||||||
const QList<Token> tokens = tokenize(src);
|
|
||||||
|
|
||||||
QCOMPARE(tokenize.state(), 1);
|
|
||||||
QCOMPARE(tokens.size(), 1);
|
|
||||||
QCOMPARE(tokens[0].f.kind, 4U);
|
|
||||||
QCOMPARE(tokens.last().f.length, 22U);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Misc::testLexerMultiLineComment2() {
|
|
||||||
const QByteArray src("");
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setQtMocRunEnabled(false);
|
|
||||||
tokenize.setObjCEnabled(false);
|
|
||||||
tokenize.setCxx0xEnabled(true);
|
|
||||||
QList<Token> tokens = tokenize(src,1);
|
|
||||||
|
|
||||||
QCOMPARE(tokenize.state(), 1);
|
|
||||||
QCOMPARE(tokens.size(), 1);
|
|
||||||
QCOMPARE(tokens[0].f.kind, 4U);
|
|
||||||
QCOMPARE(tokens[0].f.length, 1U);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Misc::testLexerMultiLineComment3() {
|
|
||||||
const QByteArray src(" ");
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setQtMocRunEnabled(false);
|
|
||||||
tokenize.setObjCEnabled(false);
|
|
||||||
tokenize.setCxx0xEnabled(true);
|
|
||||||
const QList<Token> tokens = tokenize(src,1);
|
|
||||||
|
|
||||||
QCOMPARE(tokenize.state(), 1);
|
|
||||||
QCOMPARE(tokens.size(), 1);
|
|
||||||
QCOMPARE(tokens[0].f.kind, 4U);
|
|
||||||
QCOMPARE(tokens[0].f.length, 5U);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Misc::testLexerMultiLineComment4() {
|
|
||||||
const QByteArray src("int /* integer */ i");
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setQtMocRunEnabled(false);
|
|
||||||
tokenize.setObjCEnabled(false);
|
|
||||||
tokenize.setCxx0xEnabled(true);
|
|
||||||
const QList<Token> tokens = tokenize(src,0);
|
|
||||||
|
|
||||||
QCOMPARE(tokenize.state(), 0);
|
|
||||||
QCOMPARE(tokens.size(), 3);
|
|
||||||
QCOMPARE(tokens[1].f.kind, 4U);
|
|
||||||
QCOMPARE(tokens[1].f.length, 13U);
|
|
||||||
}
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_Misc)
|
QTEST_MAIN(tst_Misc)
|
||||||
#include "tst_misc.moc"
|
#include "tst_misc.moc"
|
||||||
|
|||||||
Reference in New Issue
Block a user