Fix the implementation of Lexer::tokenText().
authorRoberto Raggi <roberto.raggi@nokia.com>
Thu, 8 Sep 2011 10:23:16 +0000 (12:23 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 19 Sep 2011 10:07:46 +0000 (12:07 +0200)
Lexer::tokenText() should return the contents of the
string literal without the quotes.

Change-Id: I968ca2e5142d8c55c75990c24380d2faa9b313a3
Reviewed-on: http://codereview.qt-project.org/4440
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
src/declarative/qml/parser/qdeclarativejslexer.cpp
src/declarative/qml/parser/qdeclarativejslexer_p.h

index def1aa8..def027c 100644 (file)
@@ -104,6 +104,7 @@ Lexer::Lexer(Engine *engine)
     , _parenthesesCount(0)
     , _stackToken(-1)
     , _patternFlags(0)
+    , _tokenKind(0)
     , _tokenLength(0)
     , _tokenLine(0)
     , _validTokenText(false)
@@ -175,14 +176,14 @@ void Lexer::scanChar()
 int Lexer::lex()
 {
     _tokenSpell = QStringRef();
-    int token = scanToken();
+    _tokenKind = scanToken();
     _tokenLength = _codePtr - _tokenStartPtr - 1;
 
     _delimited = false;
     _restrictedKeyword = false;
 
     // update the flags
-    switch (token) {
+    switch (_tokenKind) {
     case T_LBRACE:
     case T_SEMICOLON:
         _delimited = true;
@@ -214,11 +215,11 @@ int Lexer::lex()
         break;
 
     case CountParentheses:
-        if (token == T_RPAREN) {
+        if (_tokenKind == T_RPAREN) {
             --_parenthesesCount;
             if (_parenthesesCount == 0)
                 _parenthesesState = BalancedParentheses;
-        } else if (token == T_LPAREN) {
+        } else if (_tokenKind == T_LPAREN) {
             ++_parenthesesCount;
         }
         break;
@@ -228,7 +229,7 @@ int Lexer::lex()
         break;
     } // switch
 
-    return token;
+    return _tokenKind;
 }
 
 bool Lexer::isUnicodeEscapeSequence(const QChar *chars)
@@ -541,8 +542,6 @@ again:
     case '\'':
     case '"': {
         const QChar quote = ch;
-        _validTokenText = true;
-
         bool multilineStringLiteral = false;
 
         const QChar *startCode = _codePtr;
@@ -561,6 +560,7 @@ again:
             }
         }
 
+        _validTokenText = true;
         _tokenText.resize(0);
         startCode--;
         while (startCode != _codePtr - 1) 
@@ -1010,6 +1010,9 @@ QString Lexer::tokenText() const
     if (_validTokenText)
         return _tokenText;
 
+    if (_tokenKind == T_STRING_LITERAL)
+        return QString(_tokenStartPtr + 1, _tokenLength - 2);
+
     return QString(_tokenStartPtr, _tokenLength);
 }
 
index 3080a05..34cd987 100644 (file)
@@ -193,6 +193,7 @@ private:
     int _stackToken;
 
     int _patternFlags;
+    int _tokenKind;
     int _tokenLength;
     int _tokenLine;