forked from qt-creator/qt-creator
Made the indenter more Qt friendly. Added support for moc keywords.
This commit is contained in:
@@ -76,21 +76,9 @@ const SimpleToken &BackwardsScanner::fetchToken(int i)
|
||||
QList<SimpleToken> adaptedTokens;
|
||||
for (int i = 0; i < _tokens.size(); ++i) {
|
||||
SimpleToken t = _tokens.at(i);
|
||||
if (i == 0) {
|
||||
Q_ASSERT(t.followsNewline());
|
||||
}
|
||||
t.setPosition(t.position() + blockText.length());
|
||||
t.setText(_text.midRef(t.position(), t.length()));
|
||||
|
||||
if (i == 0) {
|
||||
Q_ASSERT(t.followsNewline());
|
||||
}
|
||||
|
||||
adaptedTokens.append(t);
|
||||
|
||||
if (i == 0) {
|
||||
Q_ASSERT(adaptedTokens.last().followsNewline());
|
||||
}
|
||||
}
|
||||
|
||||
_tokens = _tokenize(blockText, previousBlockState(_block));
|
||||
@@ -111,18 +99,16 @@ int BackwardsScanner::startPosition() const
|
||||
QString BackwardsScanner::text() const
|
||||
{ return _text; }
|
||||
|
||||
QString BackwardsScanner::text(int begin, int end) const
|
||||
QString BackwardsScanner::text(int index) const
|
||||
{
|
||||
const SimpleToken &firstToken = _tokens.at(begin + _offset);
|
||||
const SimpleToken &lastToken = _tokens.at(end + _offset - 1);
|
||||
return _text.mid(firstToken.begin(), lastToken.end() - firstToken.begin());
|
||||
const SimpleToken &firstToken = _tokens.at(index + _offset);
|
||||
return _text.mid(firstToken.begin(), firstToken.length());
|
||||
}
|
||||
|
||||
QStringRef BackwardsScanner::textRef(int begin, int end) const
|
||||
QStringRef BackwardsScanner::textRef(int index) const
|
||||
{
|
||||
const SimpleToken &firstToken = _tokens.at(begin + _offset);
|
||||
const SimpleToken &lastToken = _tokens.at(end + _offset - 1);
|
||||
return _text.midRef(firstToken.begin(), lastToken.end() - firstToken.begin());
|
||||
const SimpleToken &firstToken = _tokens.at(index + _offset);
|
||||
return _text.midRef(firstToken.begin(), firstToken.length());
|
||||
}
|
||||
|
||||
int BackwardsScanner::previousBlockState(const QTextBlock &block) const
|
||||
|
||||
@@ -51,8 +51,8 @@ public:
|
||||
int startPosition() const;
|
||||
|
||||
QString text() const;
|
||||
QString text(int begin, int end) const;
|
||||
QStringRef textRef(int begin, int end) const;
|
||||
QString text(int index) const;
|
||||
QStringRef textRef(int index) const;
|
||||
|
||||
// 1-based
|
||||
SimpleToken LA(int index) const;
|
||||
|
||||
@@ -150,7 +150,7 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
|
||||
if (i == initialSize)
|
||||
return QString();
|
||||
|
||||
return scanner.text(i, initialSize);
|
||||
return scanner.text(i);
|
||||
}
|
||||
|
||||
int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) const
|
||||
|
||||
@@ -49,9 +49,9 @@ static bool shouldOverrideChar(const QChar &ch)
|
||||
}
|
||||
}
|
||||
|
||||
static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index, int startToken)
|
||||
static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index)
|
||||
{
|
||||
const QStringRef text = tk.textRef(index, startToken);
|
||||
const QStringRef text = tk.textRef(index);
|
||||
|
||||
if (text.length() < 2)
|
||||
return false;
|
||||
@@ -62,9 +62,9 @@ static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index, int s
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isCompleteCharLiteral(const BackwardsScanner &tk, int index, int startToken)
|
||||
static bool isCompleteCharLiteral(const BackwardsScanner &tk, int index)
|
||||
{
|
||||
const QStringRef text = tk.textRef(index, startToken);
|
||||
const QStringRef text = tk.textRef(index);
|
||||
|
||||
if (text.length() < 2)
|
||||
return false;
|
||||
@@ -133,7 +133,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
|
||||
if (text.length() != 1)
|
||||
qWarning() << Q_FUNC_INFO << "handle event compression";
|
||||
|
||||
if (isCompleteStringLiteral(tk, index - 1, startToken))
|
||||
if (isCompleteStringLiteral(tk, index - 1))
|
||||
return QLatin1String("\"");
|
||||
|
||||
return QString();
|
||||
@@ -141,7 +141,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
|
||||
if (text.length() != 1)
|
||||
qWarning() << Q_FUNC_INFO << "handle event compression";
|
||||
|
||||
if (isCompleteCharLiteral(tk, index - 1, startToken))
|
||||
if (isCompleteCharLiteral(tk, index - 1))
|
||||
return QLatin1String("'");
|
||||
|
||||
return QString();
|
||||
|
||||
@@ -139,27 +139,14 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
|
||||
|
||||
bool inPreproc = false;
|
||||
|
||||
bool first = true;
|
||||
|
||||
for (;;) {
|
||||
Token tk;
|
||||
lex(&tk);
|
||||
if (tk.is(T_EOF_SYMBOL))
|
||||
break;
|
||||
|
||||
Q_ASSERT(lex.tokenOffset() == tk.begin());
|
||||
Q_ASSERT(lex.tokenLength() == tk.f.length);
|
||||
|
||||
QStringRef spell = text.midRef(lex.tokenOffset(), lex.tokenLength());
|
||||
SimpleToken simpleTk(tk, spell);
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
|
||||
Q_ASSERT(tk.f.newline);
|
||||
Q_ASSERT(simpleTk.followsNewline());
|
||||
}
|
||||
|
||||
lex.setScanAngleStringLiteralTokens(false);
|
||||
|
||||
if (tk.f.newline && tk.is(T_POUND))
|
||||
|
||||
Reference in New Issue
Block a user