QmlJS indenter: Fix labelled statements and break/continue with label.

Also do some cleanup to make handling of substatements nicer.

Change-Id: I78773fc81d9b0058fa97c5cef393cca34b7fd885
Reviewed-on: http://codereview.qt-project.org/4413
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
Christian Kamm
2011-09-07 13:30:48 +02:00
parent bbc48690e8
commit 16b4a6fe73
4 changed files with 187 additions and 27 deletions

View File

@@ -252,6 +252,12 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
default: enter(expression); continue; // really? identifier and more tokens might already be gone
} break;
case expression_or_label:
switch (kind) {
case Colon: turnInto(labelled_statement); break;
default: enter(expression); continue;
} break;
case expression:
if (tryInsideExpression())
break;
@@ -346,6 +352,12 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case RightBrace: leave(true); break;
} break;
case labelled_statement:
if (tryStatement())
break;
leave(true); // error recovery
break;
case substatement:
// prefer substatement_open over block_open
if (kind != LeftBrace) {
@@ -426,7 +438,11 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case RightParenthesis: leave(); leave(true); break;
} break;
break;
case breakcontinue_statement:
switch (kind) {
case Identifier: leave(true); break;
default: leave(true); continue; // try again
} break;
case case_start:
switch (kind) {
@@ -466,11 +482,22 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
int topState = m_currentState.top().type;
// if there's no colon on the same line, it's not a label
if (topState == expression_or_label)
enter(expression);
// if not followed by an identifier on the same line, it's done
else if (topState == breakcontinue_statement)
leave(true);
topState = m_currentState.top().type;
// some states might be continued on the next line
if (topState == expression
|| topState == expression_or_objectdefinition
|| topState == objectliteral_assignment) {
enter(expression_maybe_continuation);
}
// multi-line comment start?
if (topState != multiline_comment_start
&& topState != multiline_comment_cont
&& (lexerState & Scanner::MultiLineMask) == Scanner::MultiLineComment) {
@@ -680,7 +707,6 @@ bool CodeFormatter::tryStatement()
case Break:
case Continue:
enter(breakcontinue_statement);
leave(true);
return true;
case Throw:
enter(throw_statement);
@@ -717,7 +743,10 @@ bool CodeFormatter::tryStatement()
enter(jsblock_open);
return true;
case Identifier:
enter(expression_or_label);
return true;
case Delimiter:
case Var:
case PlusPlus:
case MinusMinus:
case Import:
@@ -755,7 +784,6 @@ bool CodeFormatter::isExpressionEndState(int type) const
type == objectdefinition_open ||
type == if_statement ||
type == else_clause ||
type == do_statement ||
type == jsblock_open ||
type == substatement_open ||
type == bracket_open ||