aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/parser/qdeclarativejslexer.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2011-09-14 14:50:24 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-19 12:07:46 +0200
commite4b8bafa3be9d5c20b220349d2ffa39a3085b947 (patch)
tree3015563364539b3c1b67814ed7b09bc71bdee400 /src/declarative/qml/parser/qdeclarativejslexer.cpp
parent4a5ad697330df9efaef825b09a1957b0f040a33d (diff)
Fix automatic semicolon insertion.
The parser should insert a T_SEMICOLON token when it reaches an error state and the lookahead token is following a closing brace. Change-Id: Ib849e7fbfe50c2a3e679ae0794f5780cc0b94de5 Reviewed-on: http://codereview.qt-project.org/4896 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Diffstat (limited to 'src/declarative/qml/parser/qdeclarativejslexer.cpp')
-rw-r--r--src/declarative/qml/parser/qdeclarativejslexer.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp
index def027c1f8..dd74ffa004 100644
--- a/src/declarative/qml/parser/qdeclarativejslexer.cpp
+++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp
@@ -111,6 +111,7 @@ Lexer::Lexer(Engine *engine)
, _prohibitAutomaticSemicolon(false)
, _restrictedKeyword(false)
, _terminator(false)
+ , _followsClosingBrace(false)
, _delimited(false)
, _qmlMode(true)
{
@@ -160,6 +161,7 @@ void Lexer::setCode(const QString &code, int lineno, bool qmlMode)
_prohibitAutomaticSemicolon = false;
_restrictedKeyword = false;
_terminator = false;
+ _followsClosingBrace = false;
_delimited = false;
}
@@ -175,12 +177,15 @@ void Lexer::scanChar()
int Lexer::lex()
{
+ const int previousTokenKind = _tokenKind;
+
_tokenSpell = QStringRef();
_tokenKind = scanToken();
_tokenLength = _codePtr - _tokenStartPtr - 1;
_delimited = false;
_restrictedKeyword = false;
+ _followsClosingBrace = (previousTokenKind == T_RBRACE);
// update the flags
switch (_tokenKind) {
@@ -1044,4 +1049,17 @@ bool Lexer::prevTerminator() const
return _terminator;
}
+bool Lexer::followsClosingBrace() const
+{
+ return _followsClosingBrace;
+}
+
+bool Lexer::canInsertAutomaticSemicolon(int token) const
+{
+ return token == T_RBRACE
+ || token == EOF_SYMBOL
+ || _terminator
+ || _followsClosingBrace;
+}
+
#include "qdeclarativejskeywords_p.h"