1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQMLJSLEXER_P_H
43 #define QQMLJSLEXER_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "qqmljsglobal_p.h"
57 #include "qqmljsgrammar_p.h"
58 #include <QtCore/QString>
60 QT_QML_BEGIN_NAMESPACE
66 class QML_PARSER_EXPORT Directives {
68 virtual ~Directives() {}
70 virtual void pragmaLibrary()
74 virtual void importFile(const QString &jsfile, const QString &module)
80 virtual void importModule(const QString &uri, const QString &version, const QString &module)
88 class QML_PARSER_EXPORT Lexer: public QQmlJSGrammar
92 T_ABSTRACT = T_RESERVED_WORD,
93 T_BOOLEAN = T_RESERVED_WORD,
94 T_BYTE = T_RESERVED_WORD,
95 T_CHAR = T_RESERVED_WORD,
96 T_CLASS = T_RESERVED_WORD,
97 T_DOUBLE = T_RESERVED_WORD,
98 T_ENUM = T_RESERVED_WORD,
99 T_EXPORT = T_RESERVED_WORD,
100 T_EXTENDS = T_RESERVED_WORD,
101 T_FINAL = T_RESERVED_WORD,
102 T_FLOAT = T_RESERVED_WORD,
103 T_GOTO = T_RESERVED_WORD,
104 T_IMPLEMENTS = T_RESERVED_WORD,
105 T_INT = T_RESERVED_WORD,
106 T_INTERFACE = T_RESERVED_WORD,
107 T_LET = T_RESERVED_WORD,
108 T_LONG = T_RESERVED_WORD,
109 T_NATIVE = T_RESERVED_WORD,
110 T_PACKAGE = T_RESERVED_WORD,
111 T_PRIVATE = T_RESERVED_WORD,
112 T_PROTECTED = T_RESERVED_WORD,
113 T_SHORT = T_RESERVED_WORD,
114 T_STATIC = T_RESERVED_WORD,
115 T_SUPER = T_RESERVED_WORD,
116 T_SYNCHRONIZED = T_RESERVED_WORD,
117 T_THROWS = T_RESERVED_WORD,
118 T_TRANSIENT = T_RESERVED_WORD,
119 T_VOLATILE = T_RESERVED_WORD,
120 T_YIELD = T_RESERVED_WORD
126 UnclosedStringLiteral,
127 IllegalEscapeSequence,
128 IllegalUnicodeEscapeSequence,
130 IllegalExponentIndicator,
134 enum RegExpBodyPrefix {
140 RegExp_Global = 0x01,
141 RegExp_IgnoreCase = 0x02,
142 RegExp_Multiline = 0x04
146 Lexer(Engine *engine);
148 bool qmlMode() const;
150 QString code() const;
151 void setCode(const QString &code, int lineno, bool qmlMode = true);
155 bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix);
156 bool scanDirectives(Directives *directives);
158 int regExpFlags() const { return _patternFlags; }
159 QString regExpPattern() const { return _tokenText; }
161 int tokenKind() const { return _tokenKind; }
162 int tokenOffset() const { return _tokenStartPtr - _code.unicode(); }
163 int tokenLength() const { return _tokenLength; }
165 int tokenStartLine() const { return _tokenLine; }
166 int tokenStartColumn() const { return _tokenStartPtr - _tokenLinePtr + 1; }
168 int tokenEndLine() const;
169 int tokenEndColumn() const;
171 inline QStringRef tokenSpell() const { return _tokenSpell; }
172 double tokenValue() const { return _tokenValue; }
173 QString tokenText() const;
175 Error errorCode() const;
176 QString errorMessage() const;
178 bool prevTerminator() const;
179 bool followsClosingBrace() const;
180 bool canInsertAutomaticSemicolon(int token) const;
182 enum ParenthesesState {
189 int classify(const QChar *s, int n, bool qmlMode);
192 inline void scanChar();
194 int scanNumber(QChar ch);
196 bool isLineTerminator() const;
197 static bool isIdentLetter(QChar c);
198 static bool isDecimalDigit(ushort c);
199 static bool isHexDigit(QChar c);
200 static bool isOctalDigit(ushort c);
201 static bool isUnicodeEscapeSequence(const QChar *chars);
203 void syncProhibitAutomaticSemicolon();
204 QChar decodeUnicodeEscapeCharacter(bool *ok);
211 QString _errorMessage;
212 QStringRef _tokenSpell;
214 const QChar *_codePtr;
215 const QChar *_lastLinePtr;
216 const QChar *_tokenLinePtr;
217 const QChar *_tokenStartPtr;
222 int _currentLineNumber;
226 ParenthesesState _parenthesesState;
227 int _parenthesesCount;
236 bool _validTokenText;
237 bool _prohibitAutomaticSemicolon;
238 bool _restrictedKeyword;
240 bool _followsClosingBrace;
245 } // end of namespace QQmlJS