Commit 1bc838fd authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Handle comments at the end of braceless control statements.

parent 64a167c2
......@@ -309,6 +309,18 @@ bool QmlJSIndenter::okay(QChar typedIn, QChar okayCh) const
return typedIn == QChar() || typedIn == okayCh;
}
QmlJSScanner::Token QmlJSIndenter::lastToken() const
{
for (int index = yyLinizerState.tokens.size() - 1; index != -1; --index) {
const QmlJSScanner::Token &token = yyLinizerState.tokens.at(index);
if (token.isNot(QmlJSScanner::Token::Comment))
return token;
}
return QmlJSScanner::Token();
}
/*
Saves and restores the state of the global linizer. This enables
backtracking.
......@@ -473,7 +485,7 @@ bool QmlJSIndenter::matchBracelessControlStatement()
int delimDepth = 0;
if (! yyLinizerState.tokens.isEmpty()) {
const QmlJSScanner::Token &tk = yyLinizerState.tokens.last();
QmlJSScanner::Token tk = lastToken();
if (tk.is(QmlJSScanner::Token::Identifier) &&
yyLinizerState.line.midRef(tk.offset, tk.length) == QLatin1String("else"))
......@@ -491,6 +503,10 @@ bool QmlJSIndenter::matchBracelessControlStatement()
default:
break;
case QmlJSScanner::Token::Comment:
// skip comments
break;
case QmlJSScanner::Token::RightParenthesis:
++delimDepth;
break;
......@@ -1056,3 +1072,4 @@ int QmlJSIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar t
return qMax(0, indent);
}
......@@ -84,6 +84,8 @@ private:
int indentForContinuationLine();
int indentForStandaloneLine();
QmlJSScanner::Token lastToken() const;
private:
int ppHardwareTabSize;
int ppIndentSize;
......
......@@ -41,11 +41,9 @@ namespace QmlJS {
class QMLJS_EXPORT QmlJSScanner
{
public:
struct Token {
int offset;
int length;
enum Kind {
EndOfFile,
Keyword,
Identifier,
String,
......@@ -62,8 +60,13 @@ public:
Colon,
Comma,
Dot
} kind;
};
int offset;
int length;
Kind kind;
inline Token(): offset(0), length(0), kind(EndOfFile) {}
inline Token(int o, int l, Kind k): offset(o), length(l), kind(k) {}
inline int begin() const { return offset; }
inline int end() const { return offset + length; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment