1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEJSLEXER_P_H
43 #define QDECLARATIVEJSLEXER_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 "qdeclarativejsglobal_p.h"
58 #include <QtCore/QString>
60 QT_QML_BEGIN_NAMESPACE
62 namespace QDeclarativeJS {
67 class QML_PARSER_EXPORT Lexer
70 Lexer(Engine *eng, bool tokenizeComments = false);
73 void setCode(const QString &c, int lineno);
76 int currentLineNo() const { return yylineno; }
77 int currentColumnNo() const { return yycolumn; }
79 int tokenOffset() const { return startpos; }
80 int tokenLength() const { return pos - startpos; }
82 int startLineNo() const { return startlineno; }
83 int startColumnNo() const { return startcolumn; }
85 int endLineNo() const { return currentLineNo(); }
86 int endColumnNo() const
87 { int col = currentColumnNo(); return (col > 0) ? col - 1 : col; }
89 bool prevTerminator() const { return terminator; }
118 UnclosedStringLiteral,
119 IllegalEscapeSequence,
120 IllegalUnicodeEscapeSequence,
122 IllegalExponentIndicator,
126 enum ParenthesesState {
132 enum RegExpBodyPrefix {
137 bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix);
142 State lexerState() const
145 QString errorMessage() const
147 void setErrorMessage(const QString &err)
149 void setErrorMessage(const char *err)
150 { setErrorMessage(QString::fromLatin1(err)); }
167 // encountered delimiter like "'" and "}" on last run
172 void setDone(State s);
175 int lookupKeyword(const char *);
177 bool isWhiteSpace() const;
178 bool isLineTerminator() const;
179 bool isHexDigit(ushort c) const;
180 bool isOctalDigit(ushort c) const;
182 int matchPunctuator(ushort c1, ushort c2,
183 ushort c3, ushort c4);
184 ushort singleEscape(ushort c) const;
185 ushort convertOctal(ushort c1, ushort c2,
188 static unsigned char convertHex(ushort c1);
189 static unsigned char convertHex(ushort c1, ushort c2);
190 static QChar convertUnicode(ushort c1, ushort c2,
191 ushort c3, ushort c4);
192 static bool isIdentLetter(ushort c);
193 static bool isDecimalDigit(ushort c);
195 inline int ival() const { return qsyylval.ival; }
196 inline double dval() const { return qsyylval.dval; }
197 inline NameId *ustr() const { return qsyylval.ustr; }
199 const QChar *characterBuffer() const { return buffer16; }
200 int characterCount() const { return pos16; }
203 void record8(ushort c);
204 void record16(QChar c);
205 void recordStartPos();
207 int findReservedWord(const QChar *buffer, int size) const;
209 void syncProhibitAutomaticSemicolon();
217 int bol; // begin of line
225 // current and following unicode characters
226 ushort current, next1, next2, next3;
239 ParenthesesState parenthesesState;
240 int parenthesesCount;
241 bool prohibitAutomaticSemicolon;
242 bool tokenizeComments;
245 } // namespace QDeclarativeJS