summaryrefslogtreecommitdiffstats
path: root/src/tools/qdoc/qmlparser/qqmljslexer.cpp
diff options
context:
space:
mode:
authorMartin Smith <martin.smith@digia.com>2013-10-23 13:55:53 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-01 14:52:47 +0100
commit0b152831ccee309f020435ab0737af6c73362dec (patch)
tree328ae16d222689315cc82a75622d80fac76c69a9 /src/tools/qdoc/qmlparser/qqmljslexer.cpp
parente9fe369321939a6c1cb0ba822272875481dc038e (diff)
qdoc: Update qdoc's QML parser
Because qdoc is part of qtbase/src/tools, it is not allowed to depend on anything outside of qtbase. But qdoc uses the QML parser from qtdeclarative, so qdoc has its own copy of the QML parser sources. The QML parser has been updated to the current version for Qt 5.2. Task-number: QTBUG-34269 Change-Id: I5ac9c8ff08a3494d5c35a0014a437be88f2dc31d Reviewed-by: Simon Hausmann <simon.hausmann@digia.com> Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Nico Vertriest <nico.vertriest@digia.com>
Diffstat (limited to 'src/tools/qdoc/qmlparser/qqmljslexer.cpp')
-rw-r--r--src/tools/qdoc/qmlparser/qqmljslexer.cpp76
1 files changed, 41 insertions, 35 deletions
diff --git a/src/tools/qdoc/qmlparser/qqmljslexer.cpp b/src/tools/qdoc/qmlparser/qqmljslexer.cpp
index edd85ec878..8e8ed954ad 100644
--- a/src/tools/qdoc/qmlparser/qqmljslexer.cpp
+++ b/src/tools/qdoc/qmlparser/qqmljslexer.cpp
@@ -54,7 +54,7 @@ QT_END_NAMESPACE
using namespace QQmlJS;
-static int regExpFlagFromChar(const QChar &ch)
+static inline int regExpFlagFromChar(const QChar &ch)
{
switch (ch.unicode()) {
case 'g': return Lexer::RegExp_Global;
@@ -64,7 +64,7 @@ static int regExpFlagFromChar(const QChar &ch)
return 0;
}
-static unsigned char convertHex(ushort c)
+static inline unsigned char convertHex(ushort c)
{
if (c >= '0' && c <= '9')
return (c - '0');
@@ -74,12 +74,12 @@ static unsigned char convertHex(ushort c)
return (c - 'A' + 10);
}
-static QChar convertHex(QChar c1, QChar c2)
+static inline QChar convertHex(QChar c1, QChar c2)
{
return QChar((convertHex(c1.unicode()) << 4) + convertHex(c2.unicode()));
}
-static QChar convertUnicode(QChar c1, QChar c2, QChar c3, QChar c4)
+static inline QChar convertUnicode(QChar c1, QChar c2, QChar c3, QChar c4)
{
return QChar((convertHex(c3.unicode()) << 4) + convertHex(c4.unicode()),
(convertHex(c1.unicode()) << 4) + convertHex(c2.unicode()));
@@ -259,6 +259,7 @@ int Lexer::lex()
_parenthesesCount = 0;
break;
+ case T_ELSE:
case T_DO:
_parenthesesState = BalancedParentheses;
break;
@@ -287,7 +288,8 @@ int Lexer::lex()
break;
case BalancedParentheses:
- _parenthesesState = IgnoreParentheses;
+ if (_tokenKind != T_DO && _tokenKind != T_ELSE)
+ _parenthesesState = IgnoreParentheses;
break;
} // switch
@@ -329,6 +331,27 @@ QChar Lexer::decodeUnicodeEscapeCharacter(bool *ok)
return QChar();
}
+QChar Lexer::decodeHexEscapeCharacter(bool *ok)
+{
+ if (isHexDigit(_codePtr[0]) && isHexDigit(_codePtr[1])) {
+ scanChar();
+
+ const QChar c1 = _char;
+ scanChar();
+
+ const QChar c2 = _char;
+ scanChar();
+
+ if (ok)
+ *ok = true;
+
+ return convertHex(c1, c2);
+ }
+
+ *ok = false;
+ return QChar();
+}
+
static inline bool isIdentifierStart(QChar ch)
{
// fast path for ascii
@@ -705,35 +728,29 @@ again:
scanChar();
QChar u;
- bool ok = false;
switch (_char.unicode()) {
// unicode escape sequence
- case 'u':
+ case 'u': {
+ bool ok = false;
u = decodeUnicodeEscapeCharacter(&ok);
if (! ok) {
_errorCode = IllegalUnicodeEscapeSequence;
_errorMessage = QCoreApplication::translate("QQmlParser", "Illegal unicode escape sequence");
return T_ERROR;
}
- break;
+ } break;
// hex escape sequence
- case 'x':
- if (isHexDigit(_codePtr[0]) && isHexDigit(_codePtr[1])) {
- scanChar();
-
- const QChar c1 = _char;
- scanChar();
-
- const QChar c2 = _char;
- scanChar();
-
- u = convertHex(c1, c2);
- } else {
- u = _char;
+ case 'x': {
+ bool ok = false;
+ u = decodeHexEscapeCharacter(&ok);
+ if (!ok) {
+ _errorCode = IllegalHexadecimalEscapeSequence;
+ _errorMessage = QCoreApplication::translate("QQmlParser", "Illegal hexadecimal escape sequence");
+ return T_ERROR;
}
- break;
+ } break;
// single character escape sequence
case '\\': u = QLatin1Char('\\'); scanChar(); break;
@@ -767,22 +784,11 @@ again:
return T_ERROR;
case '\r':
- if (isLineTerminatorSequence() == 2) {
- _tokenText += QLatin1Char('\r');
- u = QLatin1Char('\n');
- } else {
- u = QLatin1Char('\r');
- }
- scanChar();
- break;
-
case '\n':
case 0x2028u:
case 0x2029u:
- u = _char;
scanChar();
- break;
-
+ continue;
default:
// non escape character
@@ -1033,7 +1039,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix)
_patternFlags = 0;
while (isIdentLetter(_char)) {
int flag = regExpFlagFromChar(_char);
- if (flag == 0) {
+ if (flag == 0 || _patternFlags & flag) {
_errorMessage = QCoreApplication::translate("QQmlParser", "Invalid regular expression flag '%0'")
.arg(QChar(_char));
return false;