Qt 4.8
qdeclarativejslexer_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QDECLARATIVEJSLEXER_P_H
43 #define QDECLARATIVEJSLEXER_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
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.
52 //
53 // We mean it.
54 //
55 
56 #include "private/qdeclarativejsglobal_p.h"
57 
58 #include <QtCore/QString>
59 
61 
62 namespace QDeclarativeJS {
63 
64 class Engine;
65 class NameId;
66 
68 {
69 public:
70  Lexer(Engine *eng, bool tokenizeComments = false);
71  ~Lexer();
72 
73  void setCode(const QString &c, int lineno);
74  int lex();
75 
76  int currentLineNo() const { return yylineno; }
77  int currentColumnNo() const { return yycolumn; }
78 
79  int tokenOffset() const { return startpos; }
80  int tokenLength() const { return pos - startpos; }
81 
82  int startLineNo() const { return startlineno; }
83  int startColumnNo() const { return startcolumn; }
84 
85  int endLineNo() const { return currentLineNo(); }
86  int endColumnNo() const
87  { int col = currentColumnNo(); return (col > 0) ? col - 1 : col; }
88 
89  bool prevTerminator() const { return terminator; }
90 
91  enum State { Start,
113  Bad };
114 
115  enum Error {
123  IllegalIdentifier
124  };
125 
129  BalancedParentheses
130  };
131 
134  EqualPrefix
135  };
136 
137  bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix);
138 
140  int flags;
141 
143  { return state; }
144 
146  { return errmsg; }
147  void setErrorMessage(const QString &err)
148  { errmsg = err; }
149  void setErrorMessage(const char *err)
150  { setErrorMessage(QString::fromLatin1(err)); }
151 
152  Error error() const
153  { return err; }
154  void clearError()
155  { err = NoError; }
156 
157 private:
159  int yylineno;
160  bool done;
161  char *buffer8;
163  uint size8, size16;
164  uint pos8, pos16;
167  // encountered delimiter like "'" and "}" on last run
168  bool delimited;
170 
172  void setDone(State s);
174  void shift(uint p);
175  int lookupKeyword(const char *);
176 
177  bool isWhiteSpace() const;
178  bool isLineTerminator() const;
179  bool isHexDigit(ushort c) const;
180  bool isOctalDigit(ushort c) const;
181 
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,
186  ushort c3) const;
187 public:
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);
194 
195  inline int ival() const { return qsyylval.ival; }
196  inline double dval() const { return qsyylval.dval; }
197  inline NameId *ustr() const { return qsyylval.ustr; }
198 
199  const QChar *characterBuffer() const { return buffer16; }
200  int characterCount() const { return pos16; }
201 
202 private:
203  void record8(ushort c);
204  void record16(QChar c);
205  void recordStartPos();
206 
207  int findReservedWord(const QChar *buffer, int size) const;
208 
209  void syncProhibitAutomaticSemicolon();
210 
211  const QChar *code;
213  int yycolumn;
214  int startpos;
217  int bol; // begin of line
218 
219  union {
220  int ival;
221  double dval;
223  } qsyylval;
224 
225  // current and following unicode characters
226  ushort current, next1, next2, next3;
227 
228  struct keyword {
229  const char *name;
230  int token;
231  };
232 
235 
236  bool wantRx;
238 
243 };
244 
245 } // namespace QDeclarativeJS
246 
248 
249 #endif
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
Definition: qbezier.cpp:289
unsigned char c[8]
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void setErrorMessage(const char *err)
void setErrorMessage(const QString &err)
#define QML_PARSER_EXPORT
const QChar * characterBuffer() const
#define QT_QML_END_NAMESPACE
unsigned int uint
Definition: qglobal.h:996
#define QT_QML_BEGIN_NAMESPACE
The State element defines configurations of objects and properties.
static bool isHexDigit(const char c)
unsigned short ushort
Definition: qglobal.h:995
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
ParenthesesState parenthesesState