From: Erik Verbruggen Date: Tue, 27 Nov 2012 14:46:05 +0000 (+0100) Subject: Enable the lexer to run in JS strict/non-strict mode as well as QML mode X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=80fd41c06019ed07eb44218c72faf54c0f7be696;p=konrad%2Fqtdeclarative.git Enable the lexer to run in JS strict/non-strict mode as well as QML mode If the lexer is running in JS mode (non-qmlMode), then allow for FutureReservedWords as identifiers. Proper strict mode handling of them should be implemented in the semantic phase. QML mode is not affected, so it will reject most FutureReservedWords, and a number of other keywords. See also ECMA-262, version 5.1, paragraph 7.6.1.2. Change-Id: Ide73a041f2dfda2de3b719d6437d517f469eb450 Reviewed-by: Lars Knoll --- diff --git a/src/qml/qml/parser/qqmljskeywords_p.h b/src/qml/qml/parser/qqmljskeywords_p.h index 5ba1c71..49ce0e2 100644 --- a/src/qml/qml/parser/qqmljskeywords_p.h +++ b/src/qml/qml/parser/qqmljskeywords_p.h @@ -56,7 +56,7 @@ static inline int classify2(const QChar *s, bool qmlMode) { if (s[0].unicode() == 'a') { if (s[1].unicode() == 's') { - return qmlMode ? Lexer::T_AS : Lexer::T_RESERVED_WORD; + return qmlMode ? Lexer::T_AS : Lexer::T_IDENTIFIER; } } else if (s[0].unicode() == 'd') { @@ -74,13 +74,13 @@ static inline int classify2(const QChar *s, bool qmlMode) { } else if (qmlMode && s[0].unicode() == 'o') { if (s[1].unicode() == 'n') { - return Lexer::T_ON; + return qmlMode ? Lexer::T_ON : Lexer::T_IDENTIFIER; } } return Lexer::T_IDENTIFIER; } -static inline int classify3(const QChar *s, bool /*qmlMode*/) { +static inline int classify3(const QChar *s, bool qmlMode) { if (s[0].unicode() == 'f') { if (s[1].unicode() == 'o') { if (s[2].unicode() == 'r') { @@ -91,7 +91,7 @@ static inline int classify3(const QChar *s, bool /*qmlMode*/) { else if (s[0].unicode() == 'i') { if (s[1].unicode() == 'n') { if (s[2].unicode() == 't') { - return Lexer::T_INT; + return qmlMode ? Lexer::T_INT : Lexer::T_IDENTIFIER; } } } @@ -119,12 +119,12 @@ static inline int classify3(const QChar *s, bool /*qmlMode*/) { return Lexer::T_IDENTIFIER; } -static inline int classify4(const QChar *s, bool /*qmlMode*/) { +static inline int classify4(const QChar *s, bool qmlMode) { if (s[0].unicode() == 'b') { if (s[1].unicode() == 'y') { if (s[2].unicode() == 't') { if (s[3].unicode() == 'e') { - return Lexer::T_BYTE; + return qmlMode ? Lexer::T_BYTE : Lexer::T_IDENTIFIER; } } } @@ -140,7 +140,7 @@ static inline int classify4(const QChar *s, bool /*qmlMode*/) { else if (s[1].unicode() == 'h') { if (s[2].unicode() == 'a') { if (s[3].unicode() == 'r') { - return Lexer::T_CHAR; + return qmlMode ? Lexer::T_CHAR : Lexer::T_IDENTIFIER; } } } @@ -165,7 +165,7 @@ static inline int classify4(const QChar *s, bool /*qmlMode*/) { if (s[1].unicode() == 'o') { if (s[2].unicode() == 't') { if (s[3].unicode() == 'o') { - return Lexer::T_GOTO; + return qmlMode ? Lexer::T_GOTO : Lexer::T_IDENTIFIER; } } } @@ -174,7 +174,7 @@ static inline int classify4(const QChar *s, bool /*qmlMode*/) { if (s[1].unicode() == 'o') { if (s[2].unicode() == 'n') { if (s[3].unicode() == 'g') { - return Lexer::T_LONG; + return qmlMode ? Lexer::T_LONG : Lexer::T_IDENTIFIER; } } } @@ -225,7 +225,7 @@ static inline int classify4(const QChar *s, bool /*qmlMode*/) { return Lexer::T_IDENTIFIER; } -static inline int classify5(const QChar *s, bool /*qmlMode*/) { +static inline int classify5(const QChar *s, bool qmlMode) { if (s[0].unicode() == 'b') { if (s[1].unicode() == 'r') { if (s[2].unicode() == 'e') { @@ -260,7 +260,7 @@ static inline int classify5(const QChar *s, bool /*qmlMode*/) { if (s[2].unicode() == 'n') { if (s[3].unicode() == 's') { if (s[4].unicode() == 't') { - return Lexer::T_CONST; + return qmlMode ? Lexer::T_CONST : Lexer::T_RESERVED_WORD; } } } @@ -280,7 +280,7 @@ static inline int classify5(const QChar *s, bool /*qmlMode*/) { if (s[2].unicode() == 'n') { if (s[3].unicode() == 'a') { if (s[4].unicode() == 'l') { - return Lexer::T_FINAL; + return qmlMode ? Lexer::T_FINAL : Lexer::T_IDENTIFIER; } } } @@ -289,7 +289,7 @@ static inline int classify5(const QChar *s, bool /*qmlMode*/) { if (s[2].unicode() == 'o') { if (s[3].unicode() == 'a') { if (s[4].unicode() == 't') { - return Lexer::T_FLOAT; + return qmlMode ? Lexer::T_FLOAT : Lexer::T_IDENTIFIER; } } } @@ -300,7 +300,7 @@ static inline int classify5(const QChar *s, bool /*qmlMode*/) { if (s[2].unicode() == 'o') { if (s[3].unicode() == 'r') { if (s[4].unicode() == 't') { - return Lexer::T_SHORT; + return qmlMode ? Lexer::T_SHORT : Lexer::T_IDENTIFIER; } } } @@ -309,7 +309,7 @@ static inline int classify5(const QChar *s, bool /*qmlMode*/) { if (s[2].unicode() == 'p') { if (s[3].unicode() == 'e') { if (s[4].unicode() == 'r') { - return Lexer::T_SUPER; + return qmlMode ? Lexer::T_SUPER : Lexer::T_IDENTIFIER; } } } @@ -358,7 +358,7 @@ static inline int classify6(const QChar *s, bool qmlMode) { if (s[3].unicode() == 'b') { if (s[4].unicode() == 'l') { if (s[5].unicode() == 'e') { - return Lexer::T_DOUBLE; + return qmlMode ? Lexer::T_DOUBLE : Lexer::T_IDENTIFIER; } } } @@ -397,7 +397,7 @@ static inline int classify6(const QChar *s, bool qmlMode) { if (s[3].unicode() == 'i') { if (s[4].unicode() == 'v') { if (s[5].unicode() == 'e') { - return Lexer::T_NATIVE; + return qmlMode ? Lexer::T_NATIVE : Lexer::T_IDENTIFIER; } } } @@ -410,7 +410,7 @@ static inline int classify6(const QChar *s, bool qmlMode) { if (s[3].unicode() == 'l') { if (s[4].unicode() == 'i') { if (s[5].unicode() == 'c') { - return qmlMode ? Lexer::T_PUBLIC : Lexer::T_RESERVED_WORD; + return qmlMode ? Lexer::T_PUBLIC : Lexer::T_IDENTIFIER; } } } @@ -447,7 +447,7 @@ static inline int classify6(const QChar *s, bool qmlMode) { if (s[3].unicode() == 't') { if (s[4].unicode() == 'i') { if (s[5].unicode() == 'c') { - return Lexer::T_STATIC; + return qmlMode ? Lexer::T_STATIC : Lexer::T_IDENTIFIER; } } } @@ -471,7 +471,7 @@ static inline int classify6(const QChar *s, bool qmlMode) { if (s[3].unicode() == 'o') { if (s[4].unicode() == 'w') { if (s[5].unicode() == 's') { - return Lexer::T_THROWS; + return qmlMode ? Lexer::T_THROWS : Lexer::T_IDENTIFIER; } } } @@ -492,7 +492,7 @@ static inline int classify6(const QChar *s, bool qmlMode) { return Lexer::T_IDENTIFIER; } -static inline int classify7(const QChar *s, bool /*qmlMode*/) { +static inline int classify7(const QChar *s, bool qmlMode) { if (s[0].unicode() == 'b') { if (s[1].unicode() == 'o') { if (s[2].unicode() == 'o') { @@ -500,7 +500,7 @@ static inline int classify7(const QChar *s, bool /*qmlMode*/) { if (s[4].unicode() == 'e') { if (s[5].unicode() == 'a') { if (s[6].unicode() == 'n') { - return Lexer::T_BOOLEAN; + return qmlMode ? Lexer::T_BOOLEAN : Lexer::T_IDENTIFIER; } } } @@ -560,7 +560,7 @@ static inline int classify7(const QChar *s, bool /*qmlMode*/) { if (s[4].unicode() == 'a') { if (s[5].unicode() == 'g') { if (s[6].unicode() == 'e') { - return Lexer::T_PACKAGE; + return qmlMode ? Lexer::T_PACKAGE : Lexer::T_IDENTIFIER; } } } @@ -573,7 +573,7 @@ static inline int classify7(const QChar *s, bool /*qmlMode*/) { if (s[4].unicode() == 'a') { if (s[5].unicode() == 't') { if (s[6].unicode() == 'e') { - return Lexer::T_PRIVATE; + return qmlMode ? Lexer::T_PRIVATE : Lexer::T_IDENTIFIER; } } } @@ -593,7 +593,7 @@ static inline int classify8(const QChar *s, bool qmlMode) { if (s[5].unicode() == 'a') { if (s[6].unicode() == 'c') { if (s[7].unicode() == 't') { - return Lexer::T_ABSTRACT; + return qmlMode ? Lexer::T_ABSTRACT : Lexer::T_IDENTIFIER; } } } @@ -661,7 +661,7 @@ static inline int classify8(const QChar *s, bool qmlMode) { if (s[5].unicode() == 'r') { if (s[6].unicode() == 't') { if (s[7].unicode() == 'y') { - return Lexer::T_PROPERTY; + return qmlMode ? Lexer::T_PROPERTY : Lexer::T_IDENTIFIER; } } } @@ -695,7 +695,7 @@ static inline int classify8(const QChar *s, bool qmlMode) { if (s[5].unicode() == 'i') { if (s[6].unicode() == 'l') { if (s[7].unicode() == 'e') { - return Lexer::T_VOLATILE; + return qmlMode ? Lexer::T_VOLATILE : Lexer::T_IDENTIFIER; } } } @@ -707,7 +707,7 @@ static inline int classify8(const QChar *s, bool qmlMode) { return Lexer::T_IDENTIFIER; } -static inline int classify9(const QChar *s, bool /*qmlMode*/) { +static inline int classify9(const QChar *s, bool qmlMode) { if (s[0].unicode() == 'i') { if (s[1].unicode() == 'n') { if (s[2].unicode() == 't') { @@ -717,7 +717,7 @@ static inline int classify9(const QChar *s, bool /*qmlMode*/) { if (s[6].unicode() == 'a') { if (s[7].unicode() == 'c') { if (s[8].unicode() == 'e') { - return Lexer::T_INTERFACE; + return qmlMode ? Lexer::T_INTERFACE : Lexer::T_IDENTIFIER; } } } @@ -736,7 +736,7 @@ static inline int classify9(const QChar *s, bool /*qmlMode*/) { if (s[6].unicode() == 't') { if (s[7].unicode() == 'e') { if (s[8].unicode() == 'd') { - return Lexer::T_PROTECTED; + return qmlMode ? Lexer::T_PROTECTED : Lexer::T_IDENTIFIER; } } } @@ -755,7 +755,7 @@ static inline int classify9(const QChar *s, bool /*qmlMode*/) { if (s[6].unicode() == 'e') { if (s[7].unicode() == 'n') { if (s[8].unicode() == 't') { - return Lexer::T_TRANSIENT; + return qmlMode ? Lexer::T_TRANSIENT : Lexer::T_IDENTIFIER; } } } @@ -768,7 +768,7 @@ static inline int classify9(const QChar *s, bool /*qmlMode*/) { return Lexer::T_IDENTIFIER; } -static inline int classify10(const QChar *s, bool /*qmlMode*/) { +static inline int classify10(const QChar *s, bool qmlMode) { if (s[0].unicode() == 'i') { if (s[1].unicode() == 'm') { if (s[2].unicode() == 'p') { @@ -779,7 +779,7 @@ static inline int classify10(const QChar *s, bool /*qmlMode*/) { if (s[7].unicode() == 'n') { if (s[8].unicode() == 't') { if (s[9].unicode() == 's') { - return Lexer::T_IMPLEMENTS; + return qmlMode ? Lexer::T_IMPLEMENTS : Lexer::T_IDENTIFIER; } } } @@ -812,7 +812,7 @@ static inline int classify10(const QChar *s, bool /*qmlMode*/) { return Lexer::T_IDENTIFIER; } -static inline int classify12(const QChar *s, bool /*qmlMode*/) { +static inline int classify12(const QChar *s, bool qmlMode) { if (s[0].unicode() == 's') { if (s[1].unicode() == 'y') { if (s[2].unicode() == 'n') { @@ -825,7 +825,7 @@ static inline int classify12(const QChar *s, bool /*qmlMode*/) { if (s[9].unicode() == 'z') { if (s[10].unicode() == 'e') { if (s[11].unicode() == 'd') { - return Lexer::T_SYNCHRONIZED; + return qmlMode ? Lexer::T_SYNCHRONIZED : Lexer::T_IDENTIFIER; } } } diff --git a/src/qml/qml/parser/qqmljslexer.cpp b/src/qml/qml/parser/qqmljslexer.cpp index 34e5d61..5eecf7b 100644 --- a/src/qml/qml/parser/qqmljslexer.cpp +++ b/src/qml/qml/parser/qqmljslexer.cpp @@ -1150,7 +1150,7 @@ bool Lexer::scanDirectives(Directives *directives) // // recognize the mandatory `as' followed by the module name // - if (! (lex() == T_RESERVED_WORD && tokenText() == QLatin1String("as"))) + if (! (lex() == T_IDENTIFIER && tokenText() == QLatin1String("as"))) return false; // expected `as' if (lex() != T_IDENTIFIER) diff --git a/src/qml/qml/parser/qqmljslexer_p.h b/src/qml/qml/parser/qqmljslexer_p.h index c725d2a..66dbb39 100644 --- a/src/qml/qml/parser/qqmljslexer_p.h +++ b/src/qml/qml/parser/qqmljslexer_p.h @@ -104,7 +104,6 @@ public: T_IMPLEMENTS = T_RESERVED_WORD, T_INT = T_RESERVED_WORD, T_INTERFACE = T_RESERVED_WORD, - T_LET = T_RESERVED_WORD, T_LONG = T_RESERVED_WORD, T_NATIVE = T_RESERVED_WORD, T_PACKAGE = T_RESERVED_WORD, @@ -116,8 +115,7 @@ public: T_SYNCHRONIZED = T_RESERVED_WORD, T_THROWS = T_RESERVED_WORD, T_TRANSIENT = T_RESERVED_WORD, - T_VOLATILE = T_RESERVED_WORD, - T_YIELD = T_RESERVED_WORD + T_VOLATILE = T_RESERVED_WORD }; enum Error {