Qt 4.8
qscriptlexer_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 QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23 
24 #ifndef QSCRIPTLEXER_P_H
25 #define QSCRIPTLEXER_P_H
26 
27 //
28 // W A R N I N G
29 // -------------
30 //
31 // This file is not part of the Qt API. It exists purely as an
32 // implementation detail. This header file may change from version to
33 // version without notice, or even be removed.
34 //
35 // We mean it.
36 //
37 
38 #include <QtCore/QString>
39 
41 
43 class QScriptNameIdImpl;
44 
45 namespace QScript {
46 
47 class Lexer
48 {
49 public:
51  ~Lexer();
52 
53  void setCode(const QString &c, int lineno);
54  int lex();
55 
56  int currentLineNo() const { return yylineno; }
57  int currentColumnNo() const { return yycolumn; }
58 
59  int startLineNo() const { return startlineno; }
60  int startColumnNo() const { return startcolumn; }
61 
62  int endLineNo() const { return currentLineNo(); }
63  int endColumnNo() const
64  { int col = currentColumnNo(); return (col > 0) ? col - 1 : col; }
65 
66  bool prevTerminator() const { return terminator; }
67 
68  enum State { Start,
80  Hex,
84  Eof,
90  Bad };
91 
92  enum Error {
101  };
102 
107  };
108 
112  };
113 
114  bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix);
115 
116  QScriptNameIdImpl *pattern;
117  int flags;
118 
120  { return state; }
121 
123  { return errmsg; }
125  { errmsg = err; }
126  void setErrorMessage(const char *err)
128 
129  Error error() const
130  { return err; }
131  void clearError()
132  { err = NoError; }
133 
134 private:
136  int yylineno;
137  bool done;
138  char *buffer8;
144  // encountered delimiter like "'" and "}" on last run
145  bool delimited;
147 
149  void setDone(State s);
151  void shift(uint p);
152  int lookupKeyword(const char *);
153 
154  bool isWhiteSpace() const;
155  bool isLineTerminator() const;
156  bool isHexDigit(ushort c) const;
157  bool isOctalDigit(ushort c) const;
158 
159  int matchPunctuator(ushort c1, ushort c2,
160  ushort c3, ushort c4);
161  ushort singleEscape(ushort c) const;
163  ushort c3) const;
164 public:
165  static unsigned char convertHex(ushort c1);
166  static unsigned char convertHex(ushort c1, ushort c2);
167  static QChar convertUnicode(ushort c1, ushort c2,
168  ushort c3, ushort c4);
169  static bool isIdentLetter(ushort c);
170  static bool isDecimalDigit(ushort c);
171 
172  inline int ival() const { return qsyylval.ival; }
173  inline double dval() const { return qsyylval.dval; }
174  inline QScriptNameIdImpl *ustr() const { return qsyylval.ustr; }
175 
176  const QChar *characterBuffer() const { return buffer16; }
177  int characterCount() const { return pos16; }
178 
179 private:
180  void record8(ushort c);
181  void record16(QChar c);
182  void recordStartPos();
183 
184  int findReservedWord(const QChar *buffer, int size) const;
185 
187 
188  const QChar *code;
190  int yycolumn;
193  int bol; // begin of line
194 
195  union {
196  int ival;
197  double dval;
198  QScriptNameIdImpl *ustr;
199  } qsyylval;
200 
201  // current and following unicode characters
203 
204  struct keyword {
205  const char *name;
206  int token;
207  };
208 
211 
212  bool wantRx;
214 
218 };
219 
220 } // namespace QScript
221 
223 
224 #endif
void shift(uint p)
int startLineNo() const
void setErrorMessage(const char *err)
void syncProhibitAutomaticSemicolon()
unsigned char c[8]
Definition: qnumeric_p.h:62
int lookupKeyword(const char *)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isLineTerminator() const
void record16(QChar c)
QScriptEnginePrivate * driver
bool isWhiteSpace() const
Error error() const
void setDone(State s)
int characterCount() const
bool isHexDigit(ushort c) const
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
State lexerState() const
static bool isIdentLetter(ushort c)
bool isOctalDigit(ushort c) const
QScriptNameIdImpl * ustr() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int matchPunctuator(ushort c1, ushort c2, ushort c3, ushort c4)
QString errorMessage() const
int currentColumnNo() const
Lexer(QScriptEnginePrivate *eng)
QScriptNameIdImpl * pattern
union QScript::Lexer::@359 qsyylval
bool scanRegExp(RegExpBodyPrefix prefix=NoPrefix)
void setErrorMessage(const QString &err)
unsigned int uint
Definition: qglobal.h:996
int ival() const
The State element defines configurations of objects and properties.
int currentLineNo() const
bool prevTerminator() const
const QChar * code
static unsigned char convertHex(ushort c1)
int endColumnNo() const
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
int findReservedWord(const QChar *buffer, int size) const
const QChar * characterBuffer() const
static bool isDecimalDigit(ushort c)
int endLineNo() const
void record8(ushort c)
ushort convertOctal(ushort c1, ushort c2, ushort c3) const
ParenthesesState parenthesesState
bool prohibitAutomaticSemicolon
double dval() const
QScriptNameIdImpl * ustr
void setCode(const QString &c, int lineno)
static QChar convertUnicode(ushort c1, ushort c2, ushort c3, ushort c4)
int startColumnNo() const
ushort singleEscape(ushort c) const