1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 ** This file is part of the QtScript module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
10 ** This file contains pre-release code and may not be distributed.
11 ** You may use this file in accordance with the terms and conditions
12 ** contained in the either Technology Preview License Agreement or the
13 ** Beta Release License Agreement.
15 ** GNU Lesser General Public License Usage
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** General Public License version 2.1 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** packaging of this file. Please review the following information to
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 ** In addition, as a special exception, Nokia gives you certain
24 ** additional rights. These rights are described in the Nokia Qt LGPL
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ** If you are unsure which license is appropriate for your use, please
37 ** contact the sales department at http://www.qtsoftware.com/contact.
40 ****************************************************************************/
42 #ifndef QSCRIPTLEXER_P_H
43 #define QSCRIPTLEXER_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 <QtCore/QString>
62 class QScriptEnginePrivate
;
63 class QScriptNameIdImpl
;
70 Lexer(QScriptEnginePrivate
*eng
);
73 void setCode(const QString
&c
, int lineno
);
76 int currentLineNo() const { return yylineno
; }
77 int currentColumnNo() const { return yycolumn
; }
79 int startLineNo() const { return startlineno
; }
80 int startColumnNo() const { return startcolumn
; }
82 int endLineNo() const { return currentLineNo(); }
83 int endColumnNo() const
84 { int col
= currentColumnNo(); return (col
> 0) ? col
- 1 : col
; }
86 bool prevTerminator() const { return terminator
; }
115 UnclosedStringLiteral
,
116 IllegalEscapeSequence
,
117 IllegalUnicodeEscapeSequence
,
119 IllegalExponentIndicator
,
123 enum ParenthesesState
{
129 enum RegExpBodyPrefix
{
134 bool scanRegExp(RegExpBodyPrefix prefix
= NoPrefix
);
136 QScriptNameIdImpl
*pattern
;
139 State
lexerState() const
142 QString
errorMessage() const
144 void setErrorMessage(const QString
&err
)
146 void setErrorMessage(const char *err
)
147 { setErrorMessage(QString::fromLatin1(err
)); }
155 QScriptEnginePrivate
*driver
;
164 // encountered delimiter like "'" and "}" on last run
169 void setDone(State s
);
172 int lookupKeyword(const char *);
174 bool isWhiteSpace() const;
175 bool isLineTerminator() const;
176 bool isHexDigit(ushort c
) const;
177 bool isOctalDigit(ushort c
) const;
179 int matchPunctuator(ushort c1
, ushort c2
,
180 ushort c3
, ushort c4
);
181 ushort
singleEscape(ushort c
) const;
182 ushort
convertOctal(ushort c1
, ushort c2
,
185 static unsigned char convertHex(ushort c1
);
186 static unsigned char convertHex(ushort c1
, ushort c2
);
187 static QChar
convertUnicode(ushort c1
, ushort c2
,
188 ushort c3
, ushort c4
);
189 static bool isIdentLetter(ushort c
);
190 static bool isDecimalDigit(ushort c
);
192 inline int ival() const { return qsyylval
.ival
; }
193 inline double dval() const { return qsyylval
.dval
; }
194 inline QScriptNameIdImpl
*ustr() const { return qsyylval
.ustr
; }
196 const QChar
*characterBuffer() const { return buffer16
; }
197 int characterCount() const { return pos16
; }
200 void record8(ushort c
);
201 void record16(QChar c
);
202 void recordStartPos();
204 int findReservedWord(const QChar
*buffer
, int size
) const;
206 void syncProhibitAutomaticSemicolon();
213 int bol
; // begin of line
218 QScriptNameIdImpl
*ustr
;
221 // current and following unicode characters
222 ushort current
, next1
, next2
, next3
;
235 ParenthesesState parenthesesState
;
236 int parenthesesCount
;
237 bool prohibitAutomaticSemicolon
;
240 } // namespace QScript
244 #endif // QT_NO_SCRIPT