forked from qt-creator/qt-creator
Implemented token-based version of QmlJSIndenter::matchBracelessControlStatement().
This commit is contained in:
@@ -472,38 +472,82 @@ bool QmlJSIndenter::matchBracelessControlStatement()
|
|||||||
{
|
{
|
||||||
int delimDepth = 0;
|
int delimDepth = 0;
|
||||||
|
|
||||||
if (yyLine->endsWith(QLatin1String("else")))
|
if (! yyLinizerState.tokens.isEmpty()) {
|
||||||
return true;
|
const QmlJSScanner::Token &tk = yyLinizerState.tokens.last();
|
||||||
|
|
||||||
if (!yyLine->endsWith(QLatin1String(")")))
|
if (tk.is(QmlJSScanner::Token::Identifier) &&
|
||||||
return false;
|
yyLinizerState.line.midRef(tk.offset, tk.length) == QLatin1String("else"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
else if (tk.isNot(QmlJSScanner::Token::RightParenthesis))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < SmallRoof; i++) {
|
for (int i = 0; i < SmallRoof; i++) {
|
||||||
int j = yyLine->length();
|
for (int tokenIndex = yyLinizerState.tokens.size() - 1; tokenIndex != -1; --tokenIndex) {
|
||||||
while (j > 0) {
|
const QmlJSScanner::Token &token = yyLinizerState.tokens.at(tokenIndex);
|
||||||
j--;
|
|
||||||
QChar ch = yyLine->at(j);
|
|
||||||
|
|
||||||
switch (ch.unicode()) {
|
switch (token.kind) {
|
||||||
case ')':
|
default:
|
||||||
delimDepth++;
|
|
||||||
break;
|
break;
|
||||||
case '(':
|
|
||||||
delimDepth--;
|
case QmlJSScanner::Token::RightParenthesis:
|
||||||
if (delimDepth == 0) {
|
++delimDepth;
|
||||||
if (yyLine->indexOf(iflikeKeyword) != -1) {
|
break;
|
||||||
|
|
||||||
|
case QmlJSScanner::Token::LeftBrace:
|
||||||
|
case QmlJSScanner::Token::RightBrace:
|
||||||
|
case QmlJSScanner::Token::Semicolon:
|
||||||
|
/*
|
||||||
|
We met a statement separator, but not where we
|
||||||
|
expected it. What follows is probably a weird
|
||||||
|
continuation line. Be careful with ';' in for,
|
||||||
|
though.
|
||||||
|
*/
|
||||||
|
if (token.kind != QmlJSScanner::Token::Semicolon || delimDepth == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
case QmlJSScanner::Token::LeftParenthesis:
|
||||||
|
--delimDepth;
|
||||||
|
|
||||||
|
if (delimDepth == 0 && tokenIndex > 0) {
|
||||||
|
const QmlJSScanner::Token &tk = yyLinizerState.tokens.at(tokenIndex - 1);
|
||||||
|
|
||||||
|
if (tk.is(QmlJSScanner::Token::Identifier)) {
|
||||||
|
const QStringRef tokenText = yyLinizerState.line.midRef(tk.offset, tk.length);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We have
|
We have
|
||||||
|
|
||||||
if (x)
|
if-like (x)
|
||||||
y
|
y
|
||||||
|
|
||||||
"if (x)" is not part of the statement
|
"if (x)" is not part of the statement
|
||||||
"y".
|
"y".
|
||||||
*/
|
*/
|
||||||
return true;
|
|
||||||
|
|
||||||
|
if (tk.length == 5 && tokenText == QLatin1String("catch"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
else if (tk.length == 2 && tokenText == QLatin1String("do"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
else if (tk.length == 3 && tokenText == QLatin1String("for"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
else if (tk.length == 2 && tokenText == QLatin1String("if"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
else if (tk.length == 5 && tokenText == QLatin1String("while"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
else if (tk.length == 4 && tokenText == QLatin1String("with"))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delimDepth == -1) {
|
if (delimDepth == -1) {
|
||||||
/*
|
/*
|
||||||
We have
|
We have
|
||||||
@@ -519,23 +563,14 @@ bool QmlJSIndenter::matchBracelessControlStatement()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '{':
|
|
||||||
case '}':
|
} // end of switch
|
||||||
case ';':
|
|
||||||
/*
|
|
||||||
We met a statement separator, but not where we
|
|
||||||
expected it. What follows is probably a weird
|
|
||||||
continuation line. Be careful with ';' in for,
|
|
||||||
though.
|
|
||||||
*/
|
|
||||||
if (ch != QLatin1Char(';') || delimDepth == 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!readLine())
|
if (! readLine())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user