Simplified the handling of QML/JS comments

This commit is contained in:
Roberto Raggi
2010-01-15 12:54:17 +01:00
parent ed1414a406
commit 1c3410d3df
2 changed files with 2 additions and 80 deletions

View File

@@ -222,28 +222,9 @@ QString QScriptIndenter::trimmedCodeLine(const QString &t)
trimmed.append(QLatin1Char('X')); trimmed.append(QLatin1Char('X'));
} else if (token.is(QScriptIncrementalScanner::Token::Comment)) { } else if (token.is(QScriptIncrementalScanner::Token::Comment)) {
int i = 0; for (int i = 0; i < token.length; ++i)
int e = token.length;
if (token.offset > 0 || startState == 0) {
if (token.length >= 2 && t.midRef(token.offset, 2) == QLatin1String("/*")) {
trimmed.append(QLatin1String("/*"));
i += 2;
}
}
bool needEndOfComment = false;
if (e > 2 && token.end() == t.length() && scanner.endState() != 0) {
needEndOfComment = true;
e -= 2;
}
for (; i < e; ++i)
trimmed.append(QLatin1Char(' ')); trimmed.append(QLatin1Char(' '));
if (needEndOfComment)
trimmed.append(QLatin1String("*/"));
} else { } else {
trimmed.append(t.midRef(token.offset, token.length)); trimmed.append(t.midRef(token.offset, token.length));
} }
@@ -357,39 +338,6 @@ bool QScriptIndenter::readLine()
yyLinizerState.line = trimmedCodeLine(yyLinizerState.line); yyLinizerState.line = trimmedCodeLine(yyLinizerState.line);
/*
Remove C-style comments that span multiple lines. If the
bottom line starts in a C-style comment, we are not aware
of that and eventually yyLine will contain a slash-aster.
Notice that both if's can be executed, since
yyLinizerState.inCComment is potentially set to false in
the first if. The order of the if's is also important.
*/
if (yyLinizerState.inComment) {
const QLatin1String slashAster("/*");
k = yyLinizerState.line.indexOf(slashAster);
if (k == -1) {
yyLinizerState.line.clear();
} else {
yyLinizerState.line.truncate(k);
yyLinizerState.inComment = false;
}
}
if (!yyLinizerState.inComment) {
const QLatin1String asterSlash("*/");
k = yyLinizerState.line.indexOf(asterSlash);
if (k != -1) {
for (int i = 0; i < k + 2; i++)
eraseChar(yyLinizerState.line, i, QLatin1Char(' '));
yyLinizerState.inComment = true;
}
}
/* /*
Remove preprocessor directives. Remove preprocessor directives.
*/ */
@@ -449,7 +397,6 @@ bool QScriptIndenter::readLine()
void QScriptIndenter::startLinizer() void QScriptIndenter::startLinizer()
{ {
yyLinizerState.braceDepth = 0; yyLinizerState.braceDepth = 0;
yyLinizerState.inComment = false;
yyLinizerState.pendingRightBrace = false; yyLinizerState.pendingRightBrace = false;
yyLine = &yyLinizerState.line; yyLine = &yyLinizerState.line;
@@ -499,30 +446,7 @@ int QScriptIndenter::indentWhenBottomLineStartsInMultiLineComment()
break; break;
} }
const QString codeLine = trimmedCodeLine(blockText); return indentOfLine(blockText);
int k = codeLine.lastIndexOf(QLatin1String("/*"));
if (k == -1) {
/*
We found a normal text line in a comment. Align the
bottom line with the text on this line.
*/
return indentOfLine(codeLine);
} else {
/*
The C-style comment starts on this line. If there is
text on the same line, align with it. Otherwise, align
with the slash-aster plus a given offset.
*/
int indent = columnForIndex(codeLine, k);
k += 2;
while (k < yyLine->length()) {
if (!codeLine.at(k).isSpace())
return columnForIndex(codeLine, k);
k++;
}
return indent + ppCommentOffset;
}
} }
/* /*

View File

@@ -94,13 +94,11 @@ private:
LinizerState() LinizerState()
: braceDepth(0), : braceDepth(0),
leftBraceFollows(false), leftBraceFollows(false),
inComment(false),
pendingRightBrace(false) pendingRightBrace(false)
{ } { }
int braceDepth; int braceDepth;
bool leftBraceFollows; bool leftBraceFollows;
bool inComment;
bool pendingRightBrace; bool pendingRightBrace;
QString line; QString line;
QList<QScriptIncrementalScanner::Token> tokens; QList<QScriptIncrementalScanner::Token> tokens;