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 ...@@ -309,6 +309,18 @@ bool QmlJSIndenter::okay(QChar typedIn, QChar okayCh) const
return typedIn == QChar() || typedIn == okayCh; 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 Saves and restores the state of the global linizer. This enables
backtracking. backtracking.
...@@ -473,7 +485,7 @@ bool QmlJSIndenter::matchBracelessControlStatement() ...@@ -473,7 +485,7 @@ bool QmlJSIndenter::matchBracelessControlStatement()
int delimDepth = 0; int delimDepth = 0;
if (! yyLinizerState.tokens.isEmpty()) { if (! yyLinizerState.tokens.isEmpty()) {
const QmlJSScanner::Token &tk = yyLinizerState.tokens.last(); QmlJSScanner::Token tk = lastToken();
if (tk.is(QmlJSScanner::Token::Identifier) && if (tk.is(QmlJSScanner::Token::Identifier) &&
yyLinizerState.line.midRef(tk.offset, tk.length) == QLatin1String("else")) yyLinizerState.line.midRef(tk.offset, tk.length) == QLatin1String("else"))
...@@ -491,6 +503,10 @@ bool QmlJSIndenter::matchBracelessControlStatement() ...@@ -491,6 +503,10 @@ bool QmlJSIndenter::matchBracelessControlStatement()
default: default:
break; break;
case QmlJSScanner::Token::Comment:
// skip comments
break;
case QmlJSScanner::Token::RightParenthesis: case QmlJSScanner::Token::RightParenthesis:
++delimDepth; ++delimDepth;
break; break;
...@@ -1056,3 +1072,4 @@ int QmlJSIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar t ...@@ -1056,3 +1072,4 @@ int QmlJSIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar t
return qMax(0, indent); return qMax(0, indent);
} }
...@@ -84,6 +84,8 @@ private: ...@@ -84,6 +84,8 @@ private:
int indentForContinuationLine(); int indentForContinuationLine();
int indentForStandaloneLine(); int indentForStandaloneLine();
QmlJSScanner::Token lastToken() const;
private: private:
int ppHardwareTabSize; int ppHardwareTabSize;
int ppIndentSize; int ppIndentSize;
......
...@@ -41,11 +41,9 @@ namespace QmlJS { ...@@ -41,11 +41,9 @@ namespace QmlJS {
class QMLJS_EXPORT QmlJSScanner class QMLJS_EXPORT QmlJSScanner
{ {
public: public:
struct Token { struct Token {
int offset;
int length;
enum Kind { enum Kind {
EndOfFile,
Keyword, Keyword,
Identifier, Identifier,
String, String,
...@@ -62,8 +60,13 @@ public: ...@@ -62,8 +60,13 @@ public:
Colon, Colon,
Comma, Comma,
Dot 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 Token(int o, int l, Kind k): offset(o), length(l), kind(k) {}
inline int begin() const { return offset; } inline int begin() const { return offset; }
inline int end() const { return offset + length; } 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