1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
9 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
14 ** Please review the following information to ensure the GNU Lesser General
15 ** Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
24 ** Alternatively, this file may be used in accordance with the terms and
25 ** conditions contained in a signed written agreement between you and Nokia.
27 ** If you have questions regarding the use of this file, please contact
28 ** Nokia at qt-info@nokia.com.
30 **************************************************************************/
32 #ifndef QMLJSLEXER_P_H
33 #define QMLJSLEXER_P_H
39 // This file is not part of the Qt API. It exists purely as an
40 // implementation detail. This header file may change from version to
41 // version without notice, or even be removed.
46 #include "qmljsglobal_p.h"
48 #include <QtCore/QString>
50 QT_QML_BEGIN_NAMESPACE
57 class QML_PARSER_EXPORT Lexer
60 Lexer(Engine *eng, bool tokenizeComments = false);
63 void setCode(const QString &c, int lineno);
66 int currentLineNo() const { return yylineno; }
67 int currentColumnNo() const { return yycolumn; }
69 int tokenOffset() const { return startpos; }
70 int tokenLength() const { return pos - startpos; }
72 int startLineNo() const { return startlineno; }
73 int startColumnNo() const { return startcolumn; }
75 int endLineNo() const { return currentLineNo(); }
76 int endColumnNo() const
77 { int col = currentColumnNo(); return (col > 0) ? col - 1 : col; }
79 bool prevTerminator() const { return terminator; }
108 UnclosedStringLiteral,
109 IllegalEscapeSequence,
110 IllegalUnicodeEscapeSequence,
112 IllegalExponentIndicator,
116 enum ParenthesesState {
122 enum RegExpBodyPrefix {
127 bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix);
132 State lexerState() const
135 QString errorMessage() const
137 void setErrorMessage(const QString &err)
139 void setErrorMessage(const char *err)
140 { setErrorMessage(QString::fromLatin1(err)); }
157 // encountered delimiter like "'" and "}" on last run
162 void setDone(State s);
165 int lookupKeyword(const char *);
167 bool isWhiteSpace() const;
168 bool isLineTerminator() const;
169 bool isHexDigit(ushort c) const;
170 bool isOctalDigit(ushort c) const;
172 int matchPunctuator(ushort c1, ushort c2,
173 ushort c3, ushort c4);
174 ushort singleEscape(ushort c) const;
175 ushort convertOctal(ushort c1, ushort c2,
178 static unsigned char convertHex(ushort c1);
179 static unsigned char convertHex(ushort c1, ushort c2);
180 static QChar convertUnicode(ushort c1, ushort c2,
181 ushort c3, ushort c4);
182 static bool isIdentLetter(ushort c);
183 static bool isDecimalDigit(ushort c);
185 inline int ival() const { return qsyylval.ival; }
186 inline double dval() const { return qsyylval.dval; }
187 inline NameId *ustr() const { return qsyylval.ustr; }
189 const QChar *characterBuffer() const { return buffer16; }
190 int characterCount() const { return pos16; }
193 void record8(ushort c);
194 void record16(QChar c);
195 void recordStartPos();
197 int findReservedWord(const QChar *buffer, int size) const;
199 void syncProhibitAutomaticSemicolon();
207 int bol; // begin of line
215 // current and following unicode characters
216 ushort current, next1, next2, next3;
229 ParenthesesState parenthesesState;
230 int parenthesesCount;
231 bool prohibitAutomaticSemicolon;
232 bool tokenizeComments;